Exemplo n.º 1
0
        public override ThirdpartyUserToken GetUserToken(HttpContext ctx)
        {
            string          cipher_openid = ctx.Request.Query["openid"];
            string          cipher_token  = ctx.Request.Query["token"];
            DesEncodeDecode des           = new DesEncodeDecode(this.Config.Secret);

            byte[] bytes_openid    = des.DesEncrypt(Base58.Decode(cipher_openid));
            byte[] bytes_token     = des.DesEncrypt(Base58.Decode(cipher_token));
            ThirdpartyUserToken ut = new ThirdpartyUserToken
            {
                AccessToken = Encoding.UTF8.GetString(bytes_token),
                OpenID      = Encoding.UTF8.GetString(bytes_openid)
            };

            return(ut);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取加密TOKEN
        /// </summary>
        /// <returns></returns>
        public string ToCipherToken()
        {
            Encoding  utf8      = Encoding.UTF8;
            TimeStamp stamp     = this.Expire_Time;
            string    plainText = string.Format("{0}|{1}|{2}|{3}|{4}", (int)stamp.Seconds, this.UserId, this.UserCode,
                                                this.AppId.ToString().PadLeft(5, '0'), this.Verifiable ? 1 : 0);
            var des = new DesEncodeDecode(SECRET, System.Security.Cryptography.CipherMode.ECB, System.Security.Cryptography.PaddingMode.PKCS7, true, utf8);

            byte[] input  = utf8.GetBytes(plainText);
            byte[] output = des.DesEncrypt(input);
            string base58 = Base58.Encode(output);

            return(base58);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Des加密
        /// </summary>
        /// <param name="plainText"></param>
        /// <param name="key"></param>
        /// <param name="cipherText"></param>
        /// <returns></returns>
        public static bool DesEncrypt(string plainText, string key, out string cipherText)
        {
            Encoding utf8 = Encoding.UTF8;

            try
            {
                DesEncodeDecode des = new DesEncodeDecode(key,
                                                          System.Security.Cryptography.CipherMode.ECB,
                                                          System.Security.Cryptography.PaddingMode.PKCS7,
                                                          true, utf8);
                byte[] input  = utf8.GetBytes(plainText);
                byte[] output = des.DesEncrypt(input);
                cipherText = Base58.Encode(output);
                return(true);
            }
            catch (Exception ex)
            {
                cipherText = ex.Message;
                return(false);
            }
        }