コード例 #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)));
        }
コード例 #2
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)));
        }