From: Waldemar Dick Date: 2010-07-06T19:04:58+09:00 Subject: Re: AES block cipher artifacts Hi, Am 06.07.2010 11:21, schrieb Jonathan Groll: > I've got an oddity with the AES block cipher. There are (seemingly > random) artifact bytes that block fill a block passed through the > encryption algorith. For instance, starting with "23" this gets > transformed to > "23\016\016\016\016\016\016\016\016\016\016\016\016\016\016" > The question is, how to reversibly perform the cipher without the > artifacts? like you said, you use a BLOCK cipher. So the cipher will pad any data to match its block size. In your case the block size is 32 byte big ( 256 bit key size / 8 ). > Here is a test program that shows the problem: > >[snip] > def aes_encrypt(value) > return Aes.encrypt_buffer(KEY_LENGTH, MODE, @block_secret, > @iv_secret, value) > end > > def aes_decrypt(v) > Aes.decrypt_block(KEY_LENGTH, MODE, @block_secret, @iv_secret, v) > end > end > [snip] You use encrypt_BUFFER to encrypt, but decrypt_BLOCK to decrypt. They are not symmetric. Aes.decrypt_block is a lower level method than decrypt_buffer. I don't know the API, but I guess there should be a decrypt_buffer, which removes the padding. Waldemar Dick