读书人

求加密算法解决方法

发布时间: 2012-04-02 19:58:59 作者: rapoo

求加密算法
以下是解密算法,求此算法的加密算法
private string DecryptCI(string encryptedComputerInfo)
{
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
provider.FromXmlString(this._keyValue);
byte[] rgb = Convert.FromBase64String(encryptedComputerInfo);
byte[] bytes = provider.Decrypt(rgb, false);
return Encoding.UTF8.GetString(bytes);
}

[解决办法]
//创建并返回包含当前 RSA 对象的密钥的 XML 字符串。 true 表示同时包含 RSA 公钥和私钥;false 表示仅包含公钥。
this._keyValue=provider.ToXmlString(true);
//使用 RSA 算法对数据进行加密
byte[] bytes=provider.Encrypt(byte[] rgb,false);
//使用Base64算法对数据进行加密
String encryptedComputerInfo=Convert.ToBase64String(bytes);
//encryptedComputerInfo为加密后的结果
[解决办法]

C# code
        public string RSAEncrypt(string xmlPublicKey,string m_strEncryptString )         {                         byte[] PlainTextBArray;             byte[] CypherTextBArray;             string Result;             RSACryptoServiceProvider rsa=new RSACryptoServiceProvider();             rsa.FromXmlString(xmlPublicKey);             PlainTextBArray = (new UnicodeEncoding()).GetBytes(m_strEncryptString);             CypherTextBArray = rsa.Encrypt(PlainTextBArray, false);             Result=Convert.ToBase64String(CypherTextBArray);             return Result;                     } 

读书人网 >C#

热点推荐