Skip to content

Instantly share code, notes, and snippets.

@wmene
Created May 4, 2013 21:08
Show Gist options
  • Save wmene/5518730 to your computer and use it in GitHub Desktop.
Save wmene/5518730 to your computer and use it in GitHub Desktop.
Apache Santuario implementation of W3C XML Encryption http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html#aes128-cbc. AES 128 CBC with the iv prepended to the cipher text, then base64 encoded. From org/apache/xml/security/encryption/XMLCipher.java encryptData method
// Now build up to a properly XML Encryption encoded octet stream
// IvParameterSpec iv;
byte[] iv = c.getIV();
byte[] finalEncryptedBytes = new byte[iv.length + encryptedBytes.length];
System.arraycopy(iv, 0, finalEncryptedBytes, 0, iv.length);
System.arraycopy(encryptedBytes, 0, finalEncryptedBytes, iv.length, encryptedBytes.length);
String base64EncodedEncryptedOctets = Base64.encode(finalEncryptedBytes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment