【发布时间】:2017-04-07 05:02:26
【问题描述】:
我想使用 PKCS5padding 以 AES 256 位 ECB 模式加密数据 我的ruby方法如下,这里如何使用PKCS5Padding
def encrypt(raw_data,key)
cipher = OpenSSL::Cipher::AES.new(256, :ECB)
cipher.encrypt
cipher.key = key
encrypted_data = cipher.update(raw_data) + cipher.final
end
这里的key是OpenSSL::PKey::RSA类型,抛出no implicit conversion of OpenSSL::PKey::RSA into String异常
【问题讨论】:
-
在加密之前尝试 Base64.encode64(raw_data),我认为您正在尝试加密 RSA 密钥,对吗?
-
您可以使用 cipher.random_key 作为密钥,因为它不接受字符串以外的其他格式
-
我需要从 .cer 文件中提取公钥,然后数据必须使用从 .cer 文件中获得的公钥进行加密,为此我关注了stackoverflow.com/a/1914928/4477305@Wish Zone
-
这样做之后你是不是想用私钥解密数据??
标签: ruby-on-rails ruby encryption openssl aes