EncryptedKey encryptedKey = encryptKey(document, secretKey, publicKey, keySize); String encryptionAlgorithm = getXMLEncryptionURL(secretKey.getAlgorithm(), keySize);
/** * <p> * Encrypt the Key to be transported * </p> * <p> * Data is encrypted with a SecretKey. Then the key needs to be transported to the other end where it is needed for * decryption. For the Key transport, the SecretKey is encrypted with the recipient's public key. At the receiving end, the * receiver can decrypt the Secret Key using his private key.s * </p> * * @param document * @param keyToBeEncrypted Symmetric Key (SecretKey) * @param keyUsedToEncryptSecretKey Asymmetric Key (Public Key) * @param keySize Length of the key * @return * @throws ProcessingException */ public static EncryptedKey encryptKey(Document document, SecretKey keyToBeEncrypted, PublicKey keyUsedToEncryptSecretKey, int keySize) throws ProcessingException { XMLCipher keyCipher = null; String pubKeyAlg = keyUsedToEncryptSecretKey.getAlgorithm(); try { String keyWrapAlgo = getXMLEncryptionURLForKeyUnwrap(pubKeyAlg, keySize); keyCipher = XMLCipher.getInstance(keyWrapAlgo); keyCipher.init(XMLCipher.WRAP_MODE, keyUsedToEncryptSecretKey); return keyCipher.encryptKey(document, keyToBeEncrypted); } catch (XMLEncryptionException e) { throw logger.processingError(e); } }
Element encDataElement = getNextElementNode(documentRoot.getFirstChild()); if (encDataElement == null) throw logger.domMissingElementError("No element representing the encrypted data found"); Element encKeyElement = getNextElementNode(encDataElement.getNextSibling()); if (encKeyElement == null) { Element dataElement = getNextElementNode(decryptedRoot.getFirstChild()); if (dataElement == null) throw logger.nullValueError("Data Element after encryption is null");
EncryptedKey encryptedKey = encryptKey(document, secretKey, publicKey, keySize); String encryptionAlgorithm = getXMLEncryptionURL(secretKey.getAlgorithm(), keySize);
EncryptedKey encryptedKey = encryptKey(document, secretKey, publicKey, keySize); String encryptionAlgorithm = getXMLEncryptionURL(secretKey.getAlgorithm(), keySize);