AES CBC encryption/Decryption

escapee86

Junior Member
Feb 28, 2011
1
0
0
Hi

I am using the Java cryptography extension to encrypt the following

Case #1: Encrypting 16 bytes (1 block) using AES-CBC with 128-bit key
Key : 0x06a9214036b8a15b512e03d534120006
IV : 0x3dafba429d9eb430b422da802c9fac41
Plaintext : "Single block msg"
Ciphertext: 0xe353779c1079aeb82708942dbe77181a
Source: RFC 3602

But JCE doesnt give the above output and instead gives out e353779c1079aeb82708942dbe77181ab97c825e1c78514654 2d396941bce55d .

Do you know why the discrepancy? I am tryign to get ancryption running on C++ and sending the output across to a server running Java and getting it decrypted. Sending the RFC 3602 output doesnt help in decryption as it gives an exception (Block not padded). Can someone please help here?

Thanks
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Sounds like your plaintext isn't padded properly.
strlen("Single block msg") = 17
Pad your plaintext out to a multiple of 16 = (128bits/8bits_per_byte) and try again.

Edit: Furthermore verify your endpoints are using network byte order properly.
Edit2: byte/bit confusion on my part, somehow
 
Last edited:

Cogman

Lifer
Sep 19, 2000
10,286
145
106
If I count right, you have 17 bytes listed as your cyphertext. It should be more than that if you are applying AES correctly. What you'll notice is that the first 17 bytes correspond exactly with the 17 bit output of JCE. That strikes me as unusual as a single bit change or additional byte added (even if that byte is 0) will significantly change the entire output.