Example #1
0
        /// <summary>
        /// 3DES,数据无需URLEncode
        /// </summary>
        /// <param name="source"></param>
        /// <param name="keyIndex"></param>
        /// <returns></returns>
        protected string Get3DES(byte[] source, int keyIndex)
        {
            byte[] bufferOut = null;

            BroccoliProducts.DESCrytography.TripleDES(source,
                                                      ref bufferOut, DataCommonUtils.HexToBytes(KEY[keyIndex]), DataCommonUtils.HexToBytes(KEY[0]), true);
            return(Convert.ToBase64String(bufferOut));
        }
Example #2
0
        protected byte[] DESCrypt(string source)
        {
            byte[] bufferOut  = null;
            var    crytSource = Convert.FromBase64String(source);

            BroccoliProducts.DESCrytography.TripleDES(crytSource,
                                                      ref bufferOut, DataCommonUtils.HexToBytes(KEY[_index]), DataCommonUtils.HexToBytes(KEY[0]), false);

            return(bufferOut);
        }
Example #3
0
        public static string ParseLoginResponse(string responseDecrpt, int keyIndex)
        {
            byte[] response = Convert.FromBase64String(responseDecrpt);
            string t        = System.Text.Encoding.UTF8.GetString(response, 0, response.Length);

            byte[] bufferOut = null;
            BroccoliProducts.DESCrytography.TripleDES(response, ref bufferOut, DataCommonUtils.HexToBytes(KEY[keyIndex]), DataCommonUtils.HexToBytes(KEY[0]), false);
            string userParam = System.Text.Encoding.UTF8.GetString(bufferOut, 0, bufferOut.Length);

            return(userParam);
        }
Example #4
0
        /// <summary>
        /// 3DES加密
        /// </summary>
        /// <param name="source"></param>
        /// <param name="keyIndex"></param>
        /// <returns></returns>
        protected string Get3DESClientKeys(string source, int keyIndex, bool isUrlEncode = true)
        {
            byte[] bufferOut = null;

            var src = source;

            if (isUrlEncode)
            {
                src = WebUtility.UrlEncode(source);
            }
            BroccoliProducts.DESCrytography.TripleDES(Encoding.UTF8.GetBytes(src),
                                                      ref bufferOut, DataCommonUtils.HexToBytes(KEY[keyIndex]), DataCommonUtils.HexToBytes(KEY[0]), true);
            return(Convert.ToBase64String(bufferOut));
        }
Example #5
0
        public string GetLoginUrl(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) ||
                string.IsNullOrEmpty(password))
            {
                return(string.Empty);
            }

            var userParam = WebUtility.UrlEncode(userName) + "&&"
                            + WebUtility.UrlEncode(password) + "&&"
                            + WebUtility.UrlEncode(DeviceInfoFactory.Instance.DataInfos[0].DeviceId);

            int randomKey = (new System.Random()).Next(99999);

            randomKey += 10000;  // 10000 - 109999
            int keyIndex = ((randomKey / 10000) % 11);

            _keyIndex = keyIndex;
            byte[] bufferOut = null;

            /*
             * PaddedBufferedBlockCipher cipher = null;
             * cipher = new PaddedBufferedBlockCipher(
             *  new CbcBlockCipher(new DesEdeEngine()), new Pkcs7Padding());
             *
             * KeyParameter keyParameter = new KeyParameter(Utils.HexToBytes(TripleDESKey[keyIndex]));
             * ParametersWithIV parameters = new ParametersWithIV(keyParameter, Utils.HexToBytes(TripleDESKey[0]));
             * cipher.Init(true, parameters);
             * bufferOut = cipher.DoFinal(System.Text.Encoding.UTF8.GetBytes(userParam));
             */

            BroccoliProducts.DESCrytography.TripleDES(System.Text.Encoding.UTF8.GetBytes(userParam),
                                                      ref bufferOut, DataCommonUtils.HexToBytes(KEY[keyIndex]), DataCommonUtils.HexToBytes(KEY[0]), true);

            userParam = Convert.ToBase64String(bufferOut);

            return(string.Format("http://passport.pptv.com/ClientXMLLoginV2.do?infoValue={0}&index={1,6:000000}", WebUtility.UrlEncode(userParam),
                                 randomKey));
        }