Decryption error: Padding is invalid and cannot be removed

Hi there! I just continued my cryptotool for my school and set up a gui with powershell. My problem is now, that im recieving that error. I already searched a lot and also tried to flush the last block.. it didnt work. Maybe someone has an Idea?

Here the code:

function File-Decrypt($file, $folder) { Push-Location $folder

$AESkey = Import-Clixml -Path .key.bin $AESInit = Import-Clixml -Path .init.bin $inputStream = New-Object System.IO.FileStream($file, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read) $originalDecrypted = $file.replace(".crypt", "") try { $outputStream = New-Object System.IO.FileStream($originalDecrypted, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write) $aes = New-Object System.Security.Cryptography.AesCryptoServiceProvider $cryptoStream = New-Object System.Security.Cryptography.CryptoStream($inputStream, $aes.CreateDecryptor($AESkey.Key, $AESInit.Init), [System.Security.Cryptography.CryptoStreamMode]::Read) #$cryptoStream.FlushFinalBlock() $buffer = New-Object byte[](256) while (($read = $cryptoStream.Read($buffer, 0, 256)) -gt 0) { $outputStream.Write($buffer, 0, $read) } } catch { Write-Host "File can't be Decrypted" exit } 


submitted by /u/Roebix3
[link] [comments]

Leave a Reply