次の投稿で作成されたダウンロードトークンを復号化する方法を理解しようとしています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);
}
}
私の主な関心は、日付を元に戻して現在の日付と比較し、一定期間後にトークンを期限切れにできるようにする方法です。これは一方向ハッシュを行っていませんか?