我试图弄清楚如何解密在以下帖子中创建的下载令牌https://stackoverflow.com/a/4324115/487892
public static string GetDownloadToken(int fileId)
{
byte[] idbytes = BitConverter.GetBytes(fileId); // 4 bytes
byte[] dateTimeBytes = BitConverter.GetBytes(DateTime.Now.ToBinary()); // 8 bytes
byte[] buffer = new byte[16]; // minimum for an encryption block
string password = "password";
byte[] passwordBytes = Encoding.ASCII.GetBytes(password);
Array.Copy(idbytes, 0, buffer, 0, idbytes.Length);
Array.Copy(dateTimeBytes, 0, buffer, idbytes.Length, dateTimeBytes.Length);
byte[] encryptedBuffer = new byte[256];
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
{
int count = sha1.TransformBlock(buffer, 0, buffer.Length, encryptedBuffer, 0);
return Convert.ToBase64String(encryptedBuffer, 0, count);
}
}
我的主要兴趣是如何取回日期,以便可以将其与当前日期进行比较,以便在一段时间后使令牌过期?这不是在做单向哈希吗?