@Test public void testEncryptElement() { Key aesSymmetricKey = null; Key deSedeEncryptKey = null; EncryptedKey encryptedKey = null; Element rootElement = null; try { aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); deSedeEncryptKey = EncryptTool.generateKeyEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); encryptedKey = keyCipher.encryptKey(c32Document, aesSymmetricKey); rootElement = c32Document.getDocumentElement(); String notEncrypted = documentXmlConverter .convertXmlDocToString(c32Document); documentEncrypter.encryptElement(c32Document, aesSymmetricKey, encryptedKey, rootElement); String encrypted = documentXmlConverter .convertXmlDocToString(c32Document); logger.debug("NOT ENCRYPTED--> " + notEncrypted); logger.debug("ENCRYPTED--> " + encrypted); assertNotEquals(notEncrypted, encrypted); assertTrue(XmlComparator.compareXMLs(testEncrypted, encrypted, Arrays.asList("CipherData")).similar()); } catch (Exception e) { logger.error(e.getMessage(), e); fail(e.getMessage().toString()); } }
void encryptElement(Document xmlDocument, Key encryptSymmetricKey, EncryptedKey encryptedKey, Element element) throws XMLEncryptionException, Exception { String algorithmURI = XMLCipher.AES_128; XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptSymmetricKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(xmlDocument); keyInfo.add(encryptedKey); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(xmlDocument, element, true); }
DocumentEncrypterImpl implements DocumentEncrypter { void encryptElement(Document xmlDocument, Key encryptSymmetricKey, EncryptedKey encryptedKey, Element element) throws XMLEncryptionException, Exception { String algorithmURI = XMLCipher.AES_128; XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptSymmetricKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(xmlDocument); keyInfo.add(encryptedKey); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(xmlDocument, element, true); } }
DocumentEncrypterImpl implements DocumentEncrypter { void encryptElement(Document xmlDocument, Key encryptSymmetricKey, EncryptedKey encryptedKey, Element element) throws XMLEncryptionException, Exception { String algorithmURI = XMLCipher.AES_128; XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptSymmetricKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(xmlDocument); keyInfo.add(encryptedKey); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(xmlDocument, element, true); } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); }
DocumentEncrypterImpl implements DocumentEncrypter { void encryptElement(Document xmlDocument, Key encryptSymmetricKey, EncryptedKey encryptedKey, Element element) throws XMLEncryptionException, Exception { String algorithmURI = XMLCipher.AES_128; XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptSymmetricKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(xmlDocument); keyInfo.add(encryptedKey); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(xmlDocument, element, true); } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); @Override String encryptDocument(Key deSedeEncryptKey, String document,
			RuleExecutionContainer ruleExecutionContainer); }
DocumentEncrypterImpl implements DocumentEncrypter { void encryptElement(Document xmlDocument, Key encryptSymmetricKey, EncryptedKey encryptedKey, Element element) throws XMLEncryptionException, Exception { String algorithmURI = XMLCipher.AES_128; XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptSymmetricKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(xmlDocument); keyInfo.add(encryptedKey); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(xmlDocument, element, true); } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); @Override String encryptDocument(Key deSedeEncryptKey, String document,
			RuleExecutionContainer ruleExecutionContainer);  }