/// Decodes the encrypted text using the Advanced Encryption Standard (AES) algorithm.
/// The unique identifier.
/// The timestamp.
/// The secret. Must be a 24-character unsigned alphanumeric string.
/// The text to decode.
/// The decoded text.
internal static string Decrypt(Guid Id, DateTime timestamp, string secret, string encryptedText)
{
byte[] requestBytes = Id.ToByteArray();
byte[] timestampBytes = BitConverter.GetBytes(timestamp.Ticks);
byte[] sharedSecretBytes = encoding.GetBytes(secret);
byte[] buffer = Convert.FromBase64String(encryptedText);
using (Aes aes = Aes.Create())
{
aes.KeySize = 256;
aes.BlockSize = 128;
aes.Padding = PaddingMode.PKCS7;
aes.Mode = CipherMode.CBC;
aes.Key = timestampBytes.Concat(sharedSecretBytes).ToArray();
aes.IV = requestBytes;
ICryptoTransform decryptor = aes.CreateDecryptor();
return encoding.GetString(decryptor.TransformFinalBlock(buffer, 0, buffer.Length));
}
}