use of javax.security.auth.DestroyFailedException in project cxf by apache.
the class AbstractXmlEncInHandler method decryptPayload.
protected byte[] decryptPayload(Element root, byte[] secretKeyBytes, String symEncAlgo) throws WSSecurityException {
SecretKey key = KeyUtils.prepareSecretKey(symEncAlgo, secretKeyBytes);
try {
XMLCipher xmlCipher = EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.DECRYPT_MODE, key);
byte[] decryptedContent = xmlCipher.decryptToByteArray(root);
// Clean the private key from memory now that we're finished with it
try {
key.destroy();
} catch (DestroyFailedException ex) {
// ignore
}
return decryptedContent;
} catch (XMLEncryptionException ex) {
throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, ex);
}
}
use of javax.security.auth.DestroyFailedException in project cxf by apache.
the class AbstractXmlEncInHandler method decryptSymmetricKey.
// TODO: Support symmetric keys if requested
protected byte[] decryptSymmetricKey(String base64EncodedKey, X509Certificate cert, Crypto crypto, String keyEncAlgo, String digestAlgo, Message message) throws WSSecurityException {
CallbackHandler callback = RSSecurityUtils.getCallbackHandler(message, this.getClass());
PrivateKey key = null;
try {
key = crypto.getPrivateKey(cert, callback);
} catch (Exception ex) {
throwFault("Encrypted key can not be decrypted", ex);
}
Cipher cipher = EncryptionUtils.initCipherWithKey(keyEncAlgo, digestAlgo, Cipher.DECRYPT_MODE, key);
try {
byte[] encryptedBytes = Base64Utility.decode(base64EncodedKey);
byte[] decryptedKey = cipher.doFinal(encryptedBytes);
// Clean the private key from memory now that we're finished with it
try {
key.destroy();
} catch (DestroyFailedException ex) {
// ignore
}
return decryptedKey;
} catch (Base64Exception ex) {
throwFault("Base64 decoding has failed", ex);
} catch (Exception ex) {
throwFault("Encrypted key can not be decrypted", ex);
}
return null;
}
use of javax.security.auth.DestroyFailedException in project cxf by apache.
the class CryptoUtils method wrapSecretKey.
public static byte[] wrapSecretKey(byte[] keyBytes, String keyAlgo, Key wrapperKey, KeyProperties wrapperKeyProps) throws SecurityException {
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, convertJCECipherToSecretKeyName(keyAlgo));
byte[] encryptedKey = wrapSecretKey(secretKey, wrapperKey, wrapperKeyProps);
// Here we're finished with the SecretKey we created, so we can destroy it
try {
secretKey.destroy();
} catch (DestroyFailedException e) {
// ignore
}
return encryptedKey;
}
use of javax.security.auth.DestroyFailedException in project cxf by apache.
the class HmacUtils method computeHmac.
public static byte[] computeHmac(byte[] key, Mac hmac, String data) {
SecretKeySpec secretKey = new SecretKeySpec(key, hmac.getAlgorithm());
byte[] digest = computeHmac(secretKey, hmac, data);
// Here we're finished with the SecretKey we created, so we can destroy it
try {
secretKey.destroy();
} catch (DestroyFailedException e) {
// ignore
}
return digest;
}
use of javax.security.auth.DestroyFailedException in project cxf by apache.
the class HmacUtils method computeHmac.
public static byte[] computeHmac(byte[] key, String macAlgoJavaName, AlgorithmParameterSpec spec, String data) {
Mac mac = getMac(macAlgoJavaName);
SecretKeySpec secretKey = new SecretKeySpec(key, mac.getAlgorithm());
byte[] digest = computeHmac(secretKey, mac, spec, data);
// Here we're finished with the SecretKey we created, so we can destroy it
try {
secretKey.destroy();
} catch (DestroyFailedException e) {
LOG.log(Level.FINE, "Error destroying key: {}", e.getMessage());
}
return digest;
}
Aggregations