我从以下C#
加密代码开始,并想用Ruby
. 我的问题是我不知道如何在Ruby/OpenSSL
. 我特别需要使用PKCS7
.
C# 加密
System.Security.Cryptography.Aes c = new System.Security.Cryptography.AesManaged();
c.Mode = CipherMode.CBC;
c.Padding = PaddingMode.PKCS7; # <-- how to set this in Ruby world?
c.KeySize = 256;
c.BlockSize = 128;
c.Key = key;
c.IV = iv;
...
红宝石解密
d = OpenSSL::Cipher.new('AES-128-CBC') # oops, this should have been AES-256-CBC
d.decrypt
d.key = key
d.iv = iv
...
我目前正在使用Ruby 1.9.2
,但可以使用任何必要的版本。