C # lower des encryption followed by PHP encryption does not match ~ to seek expert guidance

Source: Internet
Author: User
Tags md5 encryption php source code
C # code Preview
String Beforeencode = "usercode=18516094544&serviceid=140114021990&cporderid= 0eb44dbd78a8deef3854b18794ebff5a4312&operationtype=3&channelid=00012243&version=1.0&time= 20140923134312 "; string key =" Subs123 "; var encodebyte = Wowencryptdes (Encoding.UTF8.GetBytes (Beforeencode), key);                   String strencode = Convert.tobase64string (encodebyte); string strEncode1 = Server.URLEncode (Strencode); ///// MD5 encryption ////////
 
  
 public string MD5 (string value) {return MD5 (value, encoding.getencoding ("GBK")); }        ///// MD5 encryption ///////////
 
  
         public string MD5 (string value, System.Text.Encoding Encoding) {if (Encoding = = null)            {encoding = System.Text.Encoding.Default;            } md5cryptoserviceprovider MD5 = new MD5CryptoServiceProvider (); byte[] passkey = encoding.            GetBytes (value);            byte[] HashKey = Md5.computehash (passkey);            StringBuilder md5string = new StringBuilder ();            foreach (Byte b in HashKey) {Md5string.appendformat ("{0:x2}", b);        } return md5string.tostring ();        } private readonly Encoding s_gb2312encoding = encoding.getencoding ("GBK"); Public byte[] Wowencryptdes (byte[] Inputbytearray, string encryptkey) {using (var DCSP = new Tripledesc                Ryptoserviceprovider ()) {dcsp.mode = CIPHERMODE.CBC;                dcsp.padding = Paddingmode.zeros; byte[] RgbKey = s_gb2312encoding.getbytes (MD5 (Encryptkey). ToLower ().                Substring (0, 24));                byte[] Rgbiv = new byte[] {(byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 ', (byte) ' 0 '};  using (var mstream = new MemoryStream ()) {using (CryptoStream cstream = new                        CryptoStream (Mstream, Dcsp.createencryptor (RgbKey, Rgbiv), CryptoStreamMode.Write)) {                        Cstream.write (Inputbytearray, 0, inputbytearray.length);                        Cstream.flushfinalblock ();                    return Mstream.toarray (); }}}} After encryption result = C4DIHM%2F8YVCLP%2B%2F10QUAPC3PIYDYGZJEPBTBJR6Z2CYCH6HBQ%2BVRMQAM%2F6WAKQ5 y8kfvtmnztpja2j3e5ycf0i5utmvdno4u0981i9mrntqpmkzfhddfdic2km3t3nt8iyicz6evfhnrpjqhn1b9uhp2bebkd5ip%2bmwoajkiu% 2fmkvvlt%2fjnpsflzls%2fp5l1tvps1bpjspobayayfgjwega%3d%3d



PHP Source Code
function Encrypt ($data) {$iv = Chr (0). chr (0). chr (0). chr (0). chr (0). chr (0). chr (0). chr (0); $key = ' Subs123 ';//D Etermine key bytes from the key text, using MD5 and wrapping Around$key = MD5 ($key); Echo ' $key
'. $key. '
'; $key = $key. $key; $tripleKey = substr ($key, 0, mcrypt_get_key_size (' TripleDES ', "CBC")); Echo ' $tripleKey
'. $tripleKey. '
';//Add pkcs#7 padding$blocksize = mcrypt_get_block_size (' TripleDES ', "CBC"); $paddingSize = $blocksize-(strlen ($DATA) % $blocksize); $data. = Str_repeat (Chr ($paddingSize), $paddingSize); $encodedText = Mcrypt_encrypt (' TripleDES ', $ Triplekey, $data, "CBC", $iv); return Base64_encode ($encodedText);} =0spyfexp%2fqa0x59pk3oq%2bxeqdh6dw%2bspg8tjjedxtnvbwqu5rdzx% after encryption 2fza8skcvdztzoevmpndauhiqrwdzfmikhk1y5xgfj0foi63fjpip5cneok8bqpdfzbocxwgkukwdpsewhtmjp3orpna9cmygn% 2bkhmvvetuxs2u%2bjz6gr57%2b8tjk8f3amipgzpgnxghqmsjnivcrhp2ibxodbvgwkjg%3d%3d

Just from. NET to PHP ask for a band ~


Reply to discussion (solution)

Online and other ~~~~~

Online and other ~~~~~

If it's not my vision, then your PHP looks like tripledes instead of DES.

Resolved ...

  • 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.