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);
轉(zhuǎn)載于:https://www.cnblogs.com/prince3245/archive/2010/04/01/1702405.html
總結(jié)
- 上一篇: 母亲的革命
- 下一篇: 【探索PowerShell 】【六】脚本