|
64 | 64 |
|
65 | 65 | import javax.crypto.Cipher;
|
66 | 66 | import javax.crypto.CipherSpi;
|
| 67 | +import javax.crypto.KeyAgreement; |
| 68 | +import javax.crypto.KeyAgreementSpi; |
67 | 69 | import javax.crypto.KeyGenerator;
|
68 | 70 | import javax.crypto.KeyGeneratorSpi;
|
69 | 71 | import javax.crypto.Mac;
|
@@ -542,6 +544,30 @@ static KeyGenerator getKeyGenerator(final String algorithm, final Provider provi
|
542 | 544 | );
|
543 | 545 | }
|
544 | 546 |
|
| 547 | + /** |
| 548 | + * @note code calling this should not assume BC provider internals ! |
| 549 | + */ |
| 550 | + public static KeyAgreement getKeyAgreement(final String algorithm) throws NoSuchAlgorithmException { |
| 551 | + try { |
| 552 | + final Provider provider = getSecurityProvider(); |
| 553 | + if ( provider != null ) return getKeyAgreement(algorithm, provider); |
| 554 | + } |
| 555 | + catch (NoSuchAlgorithmException e) { } |
| 556 | + catch (SecurityException e) { debugStackTrace(e); } |
| 557 | + return KeyAgreement.getInstance(algorithm); |
| 558 | + } |
| 559 | + |
| 560 | + static KeyAgreement getKeyAgreement(final String algorithm, final Provider provider) |
| 561 | + throws NoSuchAlgorithmException { |
| 562 | + final KeyAgreementSpi spi = (KeyAgreementSpi) getImplEngine("KeyAgreement", algorithm); |
| 563 | + if ( spi == null ) throw new NoSuchAlgorithmException(algorithm + " not found"); |
| 564 | + |
| 565 | + return newInstance(KeyAgreement.class, |
| 566 | + new Class[] { KeyAgreementSpi.class, Provider.class, String.class }, |
| 567 | + new Object[] { spi, provider, algorithm } |
| 568 | + ); |
| 569 | + } |
| 570 | + |
545 | 571 | /**
|
546 | 572 | * @note code calling this should not assume BC provider internals !
|
547 | 573 | */
|
|
0 commit comments