private void RsaTest() { var key = RSAEncryptHelper.GetRSAKey(); Console.WriteLine("PublicKey:" + key.PublicKey + "\r\n"); Console.WriteLine("PrivateKey:" + key.PrivateKey + "\r\n"); string source = @"RSAEncryptHelper"; if (RSAEncryptHelper.CheckSourceValidate(source)) { string e = RSAEncryptHelper.EncryptString(source, key.PublicKey); Console.WriteLine("加密后:" + e + "\r\n"); string d = RSAEncryptHelper.DecryptString(e, key.PrivateKey); Console.WriteLine("解密后:" + d); } }
/// <summary> /// 计算指纹 /// </summary> /// <param name="signature">客户端传回的指纹</param> /// <returns></returns> private string GetSignature(string signature) { #if DEBUG var keys = RSAEncryptHelper.GetRSAKey(); string publicKey = keys.PublicKey; string privateKey = keys.PrivateKey; Trace.WriteLine("publicKey:" + publicKey); Trace.WriteLine("privateKey:" + privateKey); #endif //解密私钥客户端传回的指纹 string argSignString = RSAEncryptHelper.DecryptString(signature, PrivateKey); _logHelper.Debug("*使用私钥解密客户端传回的指纹*:" + argSignString + "\r\n"); //取解密后字符串的md5 //string md5 = Md5Helper.Md5(argSignString); return(argSignString); }