2016-04-21 73 views
1
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); 

紅寶石equivalant我c#產生public RSA key並希望相當於紅寶石上述算法加密數據。什麼是這個C#的RSACryptoServiceProvider方法

+0

我在FromXmlString任何幫助將是巨大的特別感興趣 –

回答

0

看看openssl模塊OpenSSL (Ruby(2.0.0)。還有 也是如何使用它的例子。

  1. 加密 '你好,世界!':

    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" 
    
  2. 解密:

    key.private_decrypt(Base64.decode64(enc_base64_text)) 
    # => "Hello, World!" 
    
相關問題