Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XMLCipher and PKCS#5Padding

843811Jul 28 2010 — edited Jul 30 2010
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2010
Added on Jul 28 2010
6 comments
533 views