C # Implementing Md5withrsa signatures

Source: Internet
Author: User

This is a long time ago wrote a blog, today, he found out to tidy up a blog to publish to the garden

At that time, when the docking union UnionPay did not get out, and then a chance to find a similar code reference for a while finally finished

This code is mainly to achieve the C # service side docking the mobile phone UnionPay Java side of the interface signature

I hope we can help you.

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Security.Cryptography.X509Certificates;6 usingSystem.Security.Cryptography;7 8 namespacemd5withrsatest9 {Ten      Public classMd5withrsa One     { A         Private Static Char[] Bcdlookup = {'0','1','2','3','4','5','6','7','8','9','a','b','C','D','e','F' }; -  -         /// <summary> the         ///returns the signature string for Md5withrsa -         /// </summary> -         /// <param name= "FileName" >path to the PFX certificate file</param> -         /// <param name= "password" >PFX certificate Password</param> +         /// <param name= "Strdata" >string to be signed</param> -         /// <param name= "encoding" >Character Set, default = Iso-8859-1</param> +         /// <returns>returns the signature string for Md5withrsa</returns> A          Public Static stringSignData (stringFileName,stringPasswordstringStrdata,stringencoding ="iso-8859-1") at         { - X509Certificate2 objx5092; -             if(string. Isnullorwhitespace (password)) -             { -objx5092 =NewX509Certificate2 (fileName); -}Else in             { -objx5092 =Newx509certificate2 (fileName, password); to             } +RSACryptoServiceProvider RSA = objx5092. Privatekey asRSACryptoServiceProvider; -             byte[] data =encoding.getencoding (Encoding). GetBytes (strdata); the             byte[] HashValue = RSA. SignData (data,"MD5");//using Md5withrsa signing for certificates *             returnBytestohexstr (HashValue);///Convert Signature results to 16 binary strings $         }Panax Notoginseng         /// <summary> -         ///Convert Signature results to 16 binary strings the         /// </summary> +         /// <param name= "BCD" >the byte number of the signature result</param> A         /// <returns>16 binary string</returns> the         Private Static stringBYTESTOHEXSTR (byte[] BCD) +         { -StringBuilder s =NewStringBuilder (BCD. Length *2); $              for(inti =0; I < BCD. Length; i++) $             { -S.append (bcdlookup[(bcd[i) >>4) &0x0f]); -S.append (bcdlookup[bcd[i) &0x0f]); the             } -             returns.tostring ();Wuyi         } the     } -}

C # Implementing Md5withrsa signatures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.