int dwKeySize = 1024;
rsaCryptoServiceProvider = new RSACryptoServiceProvider(dwKeySize);
rsaCryptoServiceProvider.FromXmlString(strxmlString);
byte[] bytes = Encoding.UTF8.GetBytes(strInPut);
byte[] encryptedBytes = rsaCryptoServiceProvider.Encrypt(bytes, false);
return Convert.ToBase64String(encryptedBytes);
我c#
已生成public RSA key
,并希望在ruby中加密与上述算法相当的数据。
答案 0 :(得分:0)
查看openssl
模块OpenSSL (Ruby(2.0.0)。有
也是如何使用它的例子。
加密'你好,世界!':
require 'openssl'
require 'base64'
key = OpenSSL::PKey::RSA.new(1024)
plain_text = "Hello, World!"
enc_base64_text = Base64.encode64(key.public_encrypt(plain_text))
# => "\x91W\xF9\v\xDEU|\x9E\xC6\xA6\x1C\xCF\xF5Jc\x88'\x81\xE6\xF8mpe \xF1\x86 tt\rs\xD0OC\xC0\xA8J\xF5}\x90\x89\x8A\xFE\x9Fn1\xA5\xEB5\x95\xC7DH\xF4.\xED\x17\x8C]G\xBF\xEBB\x98'\xFA\xCAGp\xFFJ\xEA*\x1A\a\xC0\x96\x88i\x9F\xCA\x80+u\t\xB6Hk\xAC\xCD\xBA\xD2\xBE\xC0o\xF0z\xA9\xCF\xA6\xFA\xC75\xDF\x9D\xE9~\xD4\xEB\xC3\xDEJ\xBEU\xBA\xD6\xEE?\x17?\xAE\xDC\xC3\xD7\xACR\xD5"
解密:
key.private_decrypt(Base64.decode64(enc_base64_text))
# => "Hello, World!"