public FileToken Decode(string tokenStr)
        {
            var encBys = _urlDataCodec.Decode(tokenStr);

            //校验签名
            var hashLen = 16;
            var mdatBys = new byte[encBys.Length - hashLen];

            Array.Copy(encBys, hashLen, mdatBys, 0, mdatBys.Length);
            var signBys = ArrayUtil.Addition(_appSecretBytes, mdatBys);
            var hashBys = Md5(signBys);

            if (!ArrayUtil.Equals(hashBys, 0, encBys, 0, hashLen))
            {
                throw new InvalidDataException("bad sign");
            }

            if (mdatBys[0] != CurrentVersion)
            {
                throw new NotSupportedException("bad token version");
            }

            //解析成对象
            var index    = 1; //忽略版本
            var pseudoId = NetBitConverter.ToUInt32(mdatBys, index);

            index += 4;
            var fileId = NetBitConverter.ToInt32(mdatBys, index);

            index += 4;
            var ownerId = NetBitConverter.ToInt32(mdatBys, index);

            index += 4;
            var mimeId = NetBitConverter.ToUInt32(mdatBys, index);

            index += 4;
            var expireTime = ToDateTime(mdatBys, index);

            index += sizeof(long);
            var fileCreateTime = ToDateTime(mdatBys, index);

            return(new FileToken
            {
                PseudoId = pseudoId,
                FileId = fileId,
                FileOwnerId = ownerId,
                MimeId = mimeId,
                ExpireTime = expireTime,
                FileCreateTime = fileCreateTime
            });
        }
 public byte[] Decode(string encedStr)
 {
     if (encedStr == null || encedStr.Length < 2)
     {
         throw new ArgumentException(nameof(encedStr));
     }
     if (encedStr[0] == UrlDataCodecV1.CurrentVersion)
     {
         return(_codecV1.Decode(encedStr));
     }
     else
     {
         return(_codecV2.Decode(encedStr));
     }
 }
        public OwnerToken Decode(string tokenStr)
        {
            var encBys = _urlDataCodec.Decode(tokenStr);

            //校验签名
            var hashLen = 20;
            var mdatBys = new byte[encBys.Length - hashLen];

            Array.Copy(encBys, hashLen, mdatBys, 0, mdatBys.Length);
            var signBys = ArrayUtil.Addition(_appSecretBytes, mdatBys);
            var hashBys = Sha1(signBys);

            if (!ArrayUtil.Equals(hashBys, 0, encBys, 0, hashLen))
            {
                throw new InvalidDataException("bad sign");
            }

            if (mdatBys[0] != CurrentVersion)
            {
                throw new NotSupportedException("bad token version");
            }

            //解析成对象
            var index     = 1; //忽略版本
            var ownerType = NetBitConverter.ToInt32(mdatBys, index);

            index += 4;
            var ownerId = NetBitConverter.ToInt32(mdatBys, index);

            index += 4;
            var expireTime = ToDateTime(mdatBys, index);

            return(new OwnerToken
            {
                OwnerType = ownerType,
                OwnerId = ownerId,
                ExpireTime = expireTime
            });
        }