我要加密使用PKCS5padding 我的紅寶石方法如下,如何在這裏使用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
這裏AES 256位ECB模式的數據的關鍵是OpenSSL的使用AES 256 ECB PKCS5Padding加密數據: :PKey :: RSA類型,投擲no implicit conversion of OpenSSL::PKey::RSA into String
異常
http://stackoverflow.com/a/36940796/3270427 – McNets
(raw_data)加密之前嘗試Base64.encode64,我想你想加密的RSA密鑰對不對? –
您可以使用cipher.random_key作爲密鑰,因爲它不會接受字符串以外的其他格式 –