如何在C#中使用MD5哈希数据签名自己的RSA私钥

时间:2019-05-10 10:57:39

标签: c# rsa md5

我想用c#中的MD5哈希数据签名自己的私钥 我有.pem格式的私钥 我不知道如何在此

中传递我的私钥

我需要使用自己的私钥对哈希数据进行签名以生成签名 任何帮助表示赞赏

    string test = cla.MD5Hash("appid=A001channel=ae0e6jm55qlq1o7fee_type=THBmch_order_no=201601031138001nonce_str=13572468total_fee=100");
    string MD5HashData = "8b4f789f8bb0bdf962e8274d40c3864e";
    string privateKey1 = "-----BEGIN RSA PRIVATE KEY-----MIICYQIBAAKBgQDVex7K03NAnr7Jm15z50drNmPuYWCThI0cmg+tpSpH6gHNoe8H6Xm4fJpx+xhdERa7WnO3MZLHFu0LTvVweq0auCiBkYjV6x8tDG1F41nWcPOSHnH/ZpZur+4u/tJzCTM4xWw9ayBNSI6syankeZzyHMz7DtQulDjWyUzwAYyiDmpRBiSxYbUnBfcDL7uiNbwaGm1dB8pEnJIw/00T69DjdcKQSH57F5HAkRHQ4j1Yo1Tz8lNCDmoK9JW4RtUM4ABimfo3X3/95XXGthGgOfH0XXY8FG6jSEypha6FkvGNzUsnQsnA+O8lBjuGmnFPw==-----END RSA PRIVATE KEY-----";



    RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
    string publicKey = RSA.ToXmlString(false);
    string privateKey = RSA.ToXmlString(true);

    // RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
    RSA.FromXmlString(privateKey);
    RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(RSA);
    RSAFormatter.SetHashAlgorithm("SHA1");
    SHA1Managed SHhash = new SHA1Managed();
    byte[] SignedHashValue = RSAFormatter.CreateSignature(SHhash.ComputeHash(new UnicodeEncoding().GetBytes(MD5HashData)));
    string signature = System.Convert.ToBase64String(SignedHashValue);

0 个答案:

没有答案