Example #1
0
        /// <summary>
        /// 生成谷歌身份证号
        /// </summary>
        /// <param name="randomNumber">随机数字长度必须小于等于10位数</param>
        /// <returns></returns>
        public static string GenerateIdentity(int randomNumber)
        {
            string origNum = randomNumber.ToString();

            if (origNum.Length <= 0)
            {
                throw new ArgumentException("randomNumber must be 10 length");
            }

            if (origNum.Length > 10)
            {
                origNum = origNum.Substring(0, 10);
            }
            else if (origNum.Length < 10)
            {
                origNum = origNum.PadLeft(10, '0');
            }
            else
            {
                //NOTING
            }

            GoogleBase32Encoder enc = new GoogleBase32Encoder();

            return(enc.Encode(Encoding.ASCII.GetBytes(origNum)));
        }
Example #2
0
        /// <summary>
        /// 根据身份证还原随机数
        /// </summary>
        /// <param name="secret">谷歌身份证字符串</param>
        /// <returns></returns>
        public static string ReductionIdentity(string secret)
        {
            if (string.IsNullOrEmpty(secret))
            {
                throw new ArgumentNullException("secret");
            }

            GoogleBase32Encoder enc = new GoogleBase32Encoder();

            return(Encoding.ASCII.GetString(enc.Decode(secret)));
        }
Example #3
0
        /// <summary>
        /// 生成谷歌身份证号
        /// </summary>
        /// <param name="keyNumber">服务端约定的10位数字</param>
        /// <returns></returns>
        public static string GenerateIdentity(string keyNumber)
        {
            if (!Regex.IsMatch(keyNumber, @"^\d{10}$", RegexOptions.IgnoreCase))
            {
                throw new ArgumentException("keyNumber must be 10 length");
            }

            GoogleBase32Encoder enc = new GoogleBase32Encoder();

            return(enc.Encode(Encoding.ASCII.GetBytes(keyNumber)));
        }