RSA加密解密
RSA中机密过程主要是针对DES对称加密的KEY
一般流程用户A用B的公钥对KEY进行加密,B收到信息后用自己的私钥进行解密获得KEY
public string RSAEncode(string originString)
{
RSAParameters PrvKeyInfo=RSAParamParser.ParseRSAParam(publicFile); //publicFile地址
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(PubKeyInfo);
byte[] data = System.Text.Encoding.Default.GetBytes(originString);
return System.Convert.ToBase64String(RSA.Encrypt(data,false));
}
public string RSADecode(byte[] encryptedData)
{
RSAParameters PrvKeyInfo=RSAParamParser.ParseRSAParam(privateFile); //privateFile地址
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSA.ImportParameters(PrvKeyInfo);
return System.Convert.ToBase64String(RSA.Decrypt(encryptedData,false));
}
如果pubkey为string格式
byte[] keyData = System.Convert.FromBase64String(pubkey);
RSAParameters param = RSAParamParser.ParseRSAParam(keyData);
posted on 2010-04-01 16:29 prince3245 阅读(1416) 评论(0) 编辑 收藏 举报