Я читаю зашифрованную дату из файла, используя AES, и при расшифровке возвращается следующая строка: ��� C l & | � = O����3 AM
У меня есть читать некоторые вещи, но до сих пор не понимаю, что происходит.
Любая помощь с благодарностью. Спасибо.
public static AesCryptoServiceProvider provider = new AesCryptoServiceProvider()
{
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7,
Key = Encoding.ASCII.GetBytes(secretKey),
IV = new byte[] { 4, 10, 221, 22, 71, 129, 95, 231, 229, 174, 247, 119, 241, 156, 249, 57 },
BlockSize = 128,
};
public static string FIPSEncryptDecrypt(string cipherText, bool Encrypt)
{
try
{
if (Encrypt)
{
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(cipherText);
ICryptoTransform cTransform = provider.CreateEncryptor(provider.Key, provider.IV);
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
else
{
byte[] toDecryptArray = Convert.FromBase64String(cipherText);
ICryptoTransform cTransform = provider.CreateDecryptor(provider.Key, provider.IV);
byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
}
}
catch (Exception ex)
{
return string.Empty;
}
}