Algoritmo de cifrado
Para cifrar/descifrar los mensajes se utilizó un algoritmo de criptografía Advanced Encryption Standard (AES). Este algoritmo de cifrado también está disponible en el proyecto. Se trata de un cifrado simétrico por bloques que utiliza la misma clave para cifrar y descifrar los datos. /// <summary>Decodes the encrypted text using the Advanced Encryption Standard (AES) algorithm.</summary>
/// <param name="Id">The unique identifier.</param>
/// <param name="timestamp">The timestamp.</param>
/// <param name="secret">The secret. Must be a 24-character unsigned alphanumeric string.</param>
/// <param name="encryptedText">The text to decode.</param>
/// <returns>The decoded text.</returns>
internal static string Decrypt(Guid Id, DateTime timestamp, string secret, string encryptedText)
{
byte[/av_questBytes = 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));
}
}