Ejemplo n.º 1
0
        /// <summary>
        /// 解密授权码
        /// </summary>
        /// <param name="sSource">授权码</param>
        /// <param name="sPrivateKey">私钥</param>
        /// <returns>授权信息</returns>
        private static AuthorizationCode Decrypt(string sSource, string sPrivateKey)
        {
            var authorizationCode = new AuthorizationCode();
            var code = RSACryptoService.DecryptString(sSource, sPrivateKey);

            authorizationCode.Mac      = code.Substring(14, 12);
            authorizationCode.Category = Convert.ToInt32(code.Substring(36, 1));
            DateTime expireTime;

            DateTime.TryParse(code.Substring(26, 10), out expireTime);
            authorizationCode.ExpireTime = expireTime;
            return(authorizationCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解密授权码
        /// </summary>
        /// <param name="sSource">授权码</param>
        /// <param name="publicKey">公钥</param>
        /// <returns>授权信息</returns>
        public static AuthorizationCode Decrypt(string sSource, string publicKey)
        {
            var authorizationCode = new AuthorizationCode();
            var code = RSACryptoService.DecryptString(sSource, publicKey);

            string[] authorizationCodes = code.Split(new string[] { Flag }, StringSplitOptions.RemoveEmptyEntries);
            if (authorizationCodes.Length < 5)
            {
                return(authorizationCode);
            }

            authorizationCode.CheckCode = authorizationCodes[1];
            authorizationCode.Category  = Convert.ToInt16(authorizationCodes[3]);
            DateTime expireTime;

            DateTime.TryParse(authorizationCodes[2], out expireTime);
            authorizationCode.ExpireTime = expireTime;

            return(authorizationCode);
        }