首頁 > 後端開發 > php教程 > C#下 des加密后跟php加密后 不匹配~求高人指点

C#下 des加密后跟php加密后 不匹配~求高人指点

WBOY
發布: 2016-06-23 13:46:17
原創
815 人瀏覽過

C#代码预览

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);                   /// <summary>        /// MD5加密        /// </summary>        /// <param name="value"></param>        /// <returns></returns>        public  string MD5(string value)        {            return MD5(value, Encoding.GetEncoding("GBK"));        }        /// <summary>        /// MD5加密        /// </summary>        /// <param name="value"></param>        /// <param name="encoding"></param>        /// <returns></returns>        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();                    }                }            }        }加密后结果 =  C4diHm%2f8YVCLp%2b%2f10QuaPC3PiyDYgzJEpBtBJR6z2cyCH6HBq%2bVrMQAM%2f6Wakq5Y8kFvtMnZtpJa2J3e5ycF0I5utMvDno4u0981I9MrnTqpmkZFhDDFdIC2kM3t3Nt8IYicZ6eVfHnrPJQhn1b9UhP2BebkD5ip%2bmwoaJkIu%2fmkVVLt%2fJnpSFlZLS%2fP5L1tvps1BPjspOBayAYfGjwEgA%3d%3d
登入後複製



PHP 源码
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</br>'.$key.'</br>';		$key = $key . $key;	$tripleKey = substr($key, 0, mcrypt_get_key_size('tripledes', "cbc"));	echo '$tripleKey</br>'.$tripleKey.'</br>';		// 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%2FzA8skcVdZtZoevMPnDaUhIQRwDzfMIkhK1Y5XGfj0FoI63fjPIp5CnEOK8bQPDfZbOcxWgKUkWDPSeWhTmJP3orpnA9CMygN%2BkHmvvetUxS2U%2BjZ6gR57%2B8Tjk8F3AmIpGZpgNXGhQMSJnivCRHp2IbxODBvGwkjg%3D%3D
登入後複製

刚从。net 转php 求带~


回复讨论(解决方案)

在线等~~~~~

在线等~~~~~

如果不是我眼花了,那你的PHP里面用的好像是tripledes而不是des。

已解决......

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板