I want to sign an own private key with MD5 Hash data in c# I have private key in .pem format I do not know how I pass my Private key in this

I need to sign my hash data with own private key to generate the signature Any help appreciate

    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 Answers