开发者

does ruby-aes use padding by default?

开发者 https://www.devze.com 2023-02-25 06:42 出处:网络
I am using the 开发者_JS百科following in a RoR project: somepass =Aes.encrypt_buffer(128, \'ECB\', some_cypher_key, nil, pain_string)

I am using the 开发者_JS百科following in a RoR project:

somepass =Aes.encrypt_buffer(128, 'ECB', some_cypher_key, nil, pain_string)

Does using this lib and method ECB use padding by default or not?

What I am ultimately trying to do is have a RoR app and a Java app be able to create the same encrypted string out of the same simple string.

In Java code I use: cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");

These two lines of code do not create the same encrypted key.


Aes.encrypt_buffer will use padding, just not that kind that you are expecting. It will pad the block with n bytes with the value of added bytes. That is to say, if it needs to add 15 bytes, it will pad with 0x0f, if it needs to add 5bytes, it will pad with 0x05. That is to say, PKCS7 as described in RFC-5652.

You should switch to openssl or use Cipher.getInstance("AES/ECB/PKCS7Padding", "BC") with java.

0

精彩评论

暂无评论...
验证码 换一张
取 消