Заполнение недопустимо и не может быть удалено при расшифровке с использованием AES.C#

Место общения программистов C#
Anonymous
Заполнение недопустимо и не может быть удалено при расшифровке с использованием AES.

Сообщение Anonymous »

После обновления RijndaelManaged до AES мой код перестал работать и выдал исключение «Заполнение недопустимо и не может быть удалено».
Мой код работал раньше, когда я использовал RijndaelManaged.< /p>

Код: Выделить всё

            // encryptedText comes as a post from another web application
public static string DecryptStringAES(string encryptedText, string key)
{
var keybytes = Encoding.UTF8.GetBytes(key);
var iv = keybytes;

var encryptStringToBytes = EncryptStringToBytes_Aes(encryptedText, keybytes, iv);

// roundtrip value is same as enryptedText -- which came from another webapp.
// Decrypt the bytes to a string.   here encryptStringToBytes is byte[80]
// this line does not throw the exception
var roundtrip = DecryptStringFromBytes_Aes(encryptStringToBytes, keybytes, iv);

//DECRYPT FROM CRIPTOJS
var encrypted = Convert.FromBase64String(roundtrip);

//here encryptStringToBytes is byte[48]
//This Line throws the exception --Padding is invalid and cannot be removed
var id = DecryptStringFromBytes_Aes(encrypted, keybytes, iv);

return id;
}

private static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
{
if (cipherText == null || cipherText.Length 

Подробнее здесь: [url]https://stackoverflow.com/questions/79090265/padding-is-invalid-and-cannot-be-removed-while-decrypting-using-aes[/url]

Вернуться в «C#»