public string Encode(OwnerToken token) { var ownerTypeBys = NetBitConverter.GetBytes(token.OwnerType); var ownerIdBys = NetBitConverter.GetBytes(token.OwnerId); var expireTimeBys = GetBytes(token.ExpireTime); var lstLen = 1 + ownerTypeBys.Length + ownerIdBys.Length + expireTimeBys.Length; var mdatLst = new List <byte>(lstLen); mdatLst.Add(CurrentVersion); mdatLst.AddRange(ownerTypeBys); mdatLst.AddRange(ownerIdBys); mdatLst.AddRange(expireTimeBys); var mdatBys = mdatLst.ToArray(); //签名 var signBys = ArrayUtil.Addition(_appSecretBytes, mdatBys); var hashBys = Sha1(signBys); //编码成字符串 var encBys = ArrayUtil.Addition(hashBys, mdatBys); return(_urlDataCodec.Encode(encBys)); }
public string Encode(FileToken token) { var pseudoIdBys = NetBitConverter.GetBytes(token.PseudoId); var fileIdBys = NetBitConverter.GetBytes(token.FileId); var ownerIdBys = NetBitConverter.GetBytes(token.FileOwnerId); var mimeBys = NetBitConverter.GetBytes(token.MimeId); var expireTimeBys = GetBytes(token.ExpireTime); var fileCreateTimeBys = GetBytes(token.FileCreateTime); var lstLen = 1 + pseudoIdBys.Length + fileIdBys.Length + ownerIdBys.Length + mimeBys.Length + expireTimeBys.Length + fileCreateTimeBys.Length; var mdatLst = new List <byte>(lstLen); mdatLst.Add(CurrentVersion); mdatLst.AddRange(pseudoIdBys); mdatLst.AddRange(fileIdBys); mdatLst.AddRange(ownerIdBys); mdatLst.AddRange(mimeBys); mdatLst.AddRange(expireTimeBys); mdatLst.AddRange(fileCreateTimeBys); var mdatBys = mdatLst.ToArray(); //签名 var signBys = ArrayUtil.Addition(_appSecretBytes, mdatBys); var hashBys = Md5(signBys); //编码成字符串 var encBys = ArrayUtil.Addition(hashBys, mdatBys); return(_urlDataCodec.Encode(encBys)); }
public string GetFileDirectoryPath(uint pseudoId, DateTime fileCreateTime, int fileId) { var pIdBys = NetBitConverter.GetBytes(pseudoId); //每个文件有一个独立的目录,用于存放各种尺寸的文件 //fileDirName = FileTableIndex_FileId var fileDirName = $"{pseudoId % _dbOption.CurrentValue.FileTableCount}_{fileId}"; //dirPath = Root/Year/Month/Day/pseudoId[0]+pseudoId[1] var dirPath = Path.Combine( _option.CurrentValue.RootPath, fileCreateTime.Year.ToString(), fileCreateTime.Month.ToString("D2"), fileCreateTime.Day.ToString("D2"), pIdBys[0].ToString("x") + pIdBys[1].ToString("x"), fileDirName ); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } return(dirPath); }
private static byte[] GetBytes(DateTime dt) { return(NetBitConverter.GetBytes(DateTimeUtil.DateTimeToUnixTimestamp(dt))); }
private static byte[] GetBytes(DateTime dt) { return(NetBitConverter.GetBytes(dt.ToBinary())); }