Hello,
how can I change the padding scheme that the XMLCipher object is using?
For encryption I use:
SecretKeyFactory desFactory = SecretKeyFactory.getInstance(algorithm);
DESedeKeySpec desedekeySpec = new DESedeKeySpec(passphraseBytes);
SecretKey encKey = desFactory.generateSecret(desedekeySpec);
Cipher cipherObj = Cipher.getInstance("DESede/CBC/PKCS#5Padding");
cipherObj.init(opmode, encKey);
CipherInputStream cis = new CipherInputStream(plaintextBytes, cipherObj);
and for decryption I use:
Key symmetricKey = GenerateDataEncryptionKey();
String algorithmURI = XMLCipher.TRIPLEDES;
XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI);
xmlCipher.init(XMLCipher.DECRYPT_MODE, symmetricKey);
xmlCipher.doFinal(document, encryptedDataElement);
If I use the second code to decrypt (DESede, CBC, PKCS#5 padding, BASE64)-Characters, I get an error:
Exception in thread "main" org.apache.xml.security.encryption.XMLEncryptionException: Given final block not properly padded
Original Exception was javax.crypto.BadPaddingException: Given final block not properly padded
XMLCipher.TRIPLEDES is DESede with CBC but I think the XMLCipher doesn't use PKCS#5Padding.
How can I set the padding of the XMLCipher object?