dbf.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
EncryptionMethod em =
new EncryptionMethod(doc, EncryptionConstants.ALGO_ID_KEYWRAP_AES128);
Key wrapKey = em.createSecretKeyFromBytes(
org.apache.xml.security.utils.HexDump.hexStringToByteArray(
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
Key contentKey = em.createSecretKeyFromBytes(
org.apache.xml.security.utils.HexDump.hexStringToByteArray(
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
byte ciphertext[] = em.wrap(contentKey, wrapKey);
KeyInfo ki = new KeyInfo(doc);
ki.add(new org.apache.xml.security.keys.content.KeyName(doc,
"Christian Geuer-Pollmann"));
EncryptedKey ed = new EncryptedKey(doc, em, ki,
new CipherData(doc, ciphertext), null,
null, "Christian Geuer-Pollmann", "",
EncryptionConstants.TYPE_CONTENT,
"Ed Simon");
doc.appendChild(ed.getElement());
org.apache.xml.security.utils.XMLUtils.outputDOMc14nWithComments(doc,
System.out);
EncryptionMethod em2 = ed.getEncryptionMethod();
byte[] ciphertext2 = ed.getCipherData().getCipherValue().getCipherText();
Key decrypt = em2.createSecretKeyFromBytes(
org.apache.xml.security.utils.HexDump.hexStringToByteArray(
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
Key unwrapped =
em2.unwrap(ciphertext2, wrapKey,
EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
System.out.println();
System.out.println();
System.out.println();