See many online implementations of the MD5WITHRSA algorithm using C #, are used by the certificate, by loading the certificate and certificate password encryption.
But in practice, we also have the situation through the key encryption, if found a long time finally found the method, the first to download a BouncyCastle.Crypto.dll.
Words not much to say, paste code:
public classMd5withrsa {public static Encoding Encoding = Encoding.GetEncoding ("GBK"); public static string signersymbol = "Md5withrsa"; PublicMd5withrsa () {} public Md5withrsa (Encoding E, strings) {encoding =E Signersymbol =S } private static Asymmetrickeyparameter CreateKEY (bool isprivate, stringKey) {byte[] Keyinfobyte =Convert.frombase64string (key); If(isprivate) returnPrivatekeyfactory.createkey (Keyinfobyte); else returnPublickeyfactory.createkey (Keyinfobyte); }///<summary>//Data encryption//</summary>//<param name= "content" > Strings to be encrypted </param>//<param Nam E= "Privatekey" > Private keys </param>//<returns> encrypted strings </returns> public static string sign (string content , stringPrivatekey) {Isigner sig =Signerutilities.getsigner (Signersymbol); Sig. Init (True, CreateKEY (True, Privatekey)); var bytes =Encoding. GetBytes (content); Sig. Blockupdate (Bytes, 0, bytes. Length); Byte[] Signature =Sig. Generatesignature (); /* Base encode the sig so it 8-bit clean */var signedstring = convert.tobase64string (signature); return signedstring;}///<summary>//verification signature///</summary> <param name= "Content" > Strings to be signed </param>//<param name= "SignData" > Encrypted text </param>//< param name= "PublicKey" > Public key text </param>//<returns> Whether or not it is the same </returns> publicly static bool Verify (string Content, String signdata, String publickey) {Isigner signer = Signerutilities.getsigner (signersymbol); Signer. Init (False, CreateKEY (false , PublicKey)), var expectedsig = convert.frombase64string (signdata);/* Get the Bytes to is signed from the string */var msgbytes = encoding. GetBytes (content); /* Calculate the signature and see if it matches */ signer. Blockupdate (msgbytes, 0 , msgbytes.length); return signer. VerifySignature (Expectedsig); } }
In this way, we use the sign () method to encrypt and verify the signature through the Verify () method.
Here you will find a set of data to verify:
Private key: miicdqibadanbgkqhkig9w0baqefaascal8wggjbageaaogbajmr8nnrv7ve7y5febium/tsu0fk5nvzvfpsyxpaqhbxy+ en0bi2jeg790c1njk9q3u36u2jbdhaidiomlgh6wwkjsfn7dghv/fcwsx1vvj+drinzy1432fraj8gqspvmnebpeljbe94iwlwkpn+aor+ bnx8ql/uhmfcplvqxos9agmbaaecgyazqbms434m50ubmmfkknf6kxnrgnpodbfktlo7ftybu/ hf6tfp21a1pme5iyhfk5aasbz6ocuoygwfhhdyzn+5w+dwef3kp1rle4y5cjwqnlk/g22tandf9znh/lthflvittoqu/eh/ 34te1gynxrbsi1olw/1wv8zrjm3vtm9qqjbanvnwfq+cjhuyfzkxqb7+ ycqfny8wdq8uw2hv9zmjginth7fsljtdu5mayppo6f74slo5tfumnp7evppqsjyankcqqcrad6ikho+ oilvvyikimxatjgd7n1gnhq5crhunpwlhwv/ih2d3jjdf8iuzopijfuxtfm2fzyi+ evdsv6s4rcfakagjnybnighogcujzyd6q3svxvkrqev3ubws2hrh/lna4l8cakqxcq8jfwlkod8/ qugfilywbqizqx4vmdjhtfzakbsal9dbwzcapvpxp/4jwgpxdlhz9nlv/ku4bvvkoobq++ Yuhwkygyodvcd5mlikosnq5hzp0vw14lwvuf2bmxfakbunrzksvuulniawdkd4rq6gvzuxxuizw0ze6athydixpb4jvajkrtlxzav1qh9cr1znjlcg +rbgyudf9t4a9n5
Public key: migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqctk/dz0ve73u2orrayrpv07fnhyutb87xabgmtweiqv2phddaytirio/datz45pun1n+ Rtiqqxwigykjpyiesfpcbbz+3yivf3wlkl9vvsfnusdwcten9n0wifbqrkbzj3gaxi4wxvecmjviqtfgdkfgtv/ec/7h5nwj5vuf6lpqidaqab
"China"
Signature Result: yrzydpfg0yomjfcm4rbo7wcyrn3lgypg52f0tvbj1palywd1y7yi+vjj+g4xftvtaxz7cwcabth8j/ 8wwgujyjpg5vdkkjzkd8jr1yadaagmsl43weeeovj+fjdht/vltkj8chnjaxagiilfcenf9x8xlmgbvh2tj0myhzat55u=
There is also a Web site where MD5WITHRSA encryption verification can be performed online: www.yunsos.com/Md5WithRSA.aspx can be verified online.
Hope to be able to help everyone!
Implementing the standard MD5WITHRSA algorithm in C #