C # des encryption does not match with php encryption ~ Please advise

Source: Internet
Author: User
C # des encryption does not match with php encryption ~ Please advise C # code preview
String beforeEncode = "usercode = 18516094544 & serviceid = 140114021990 & cporderid = partner & 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 TripleDESCryptoServiceProvider () {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 () ;}}} encrypted result = C4diHm % 2f8YVCLp % 2b % found % 2 bVrMQAM % found % 2 bmwoaJkIu % 2 fmkVVLt % 2 fJnpSFlZLS % 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'; // determine 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);} after encryption = 0 SPyfexP % 2FQA0x59PK3oQ % 2BxeQDh6Dw % signature % %2bkhmvvetuxs2u % 2BjZ6gR57% 3D % 3D % 3D

Just now. Net to php for bandwidth ~


Reply to discussion (solution)

Online, etc ~~~~~

Online, etc ~~~~~

If it's not my eye-catching, you use tripledes instead of des in PHP.

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.