Search in sources :

Example 56 with KeyAgreement

use of javax.crypto.KeyAgreement in project cxf by apache.

the class JweUtils method generateKeyZ.

private static byte[] generateKeyZ(ECPrivateKey privateKey, ECPublicKey publicKey) {
    try {
        KeyAgreement ka = KeyAgreement.getInstance("ECDH");
        ka.init(privateKey);
        ka.doPhase(publicKey, true);
        return ka.generateSecret();
    } catch (Exception ex) {
        LOG.warning("Derived key calculation problem");
        throw new JweException(JweException.Error.KEY_ENCRYPTION_FAILURE);
    }
}
Also used : KeyAgreement(javax.crypto.KeyAgreement)

Aggregations

KeyAgreement (javax.crypto.KeyAgreement)56 KeyPairGenerator (java.security.KeyPairGenerator)15 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 InvalidKeyException (java.security.InvalidKeyException)12 KeyFactory (java.security.KeyFactory)12 SecretKey (javax.crypto.SecretKey)10 DHParameterSpec (javax.crypto.spec.DHParameterSpec)10 KeyPair (java.security.KeyPair)9 Cipher (javax.crypto.Cipher)9 IOException (java.io.IOException)7 PublicKey (java.security.PublicKey)7 BigInteger (java.math.BigInteger)6 SecureRandom (java.security.SecureRandom)6 DHPublicKey (javax.crypto.interfaces.DHPublicKey)6 SecretKeySpec (javax.crypto.spec.SecretKeySpec)6 GeneralSecurityException (java.security.GeneralSecurityException)5 DHPublicKeySpec (javax.crypto.spec.DHPublicKeySpec)5 IvParameterSpec (javax.crypto.spec.IvParameterSpec)5 PrivateKey (java.security.PrivateKey)4 CertificateException (java.security.cert.CertificateException)4