誰かが親切に次の質問を手伝ってくれますか
function Decrypt-String($Encrypted, $Passphrase, $salt, $init)
{
if($Encrypted -is [string]){
$Encrypted = [Convert]::FromBase64String($Encrypted)
}
$r = new-Object System.Security.Cryptography.RijndaelManaged
$pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
$salt = [Text.Encoding]::UTF8.GetBytes($salt)
$r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
$r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
$d = $r.CreateDecryptor()
$ms = new-Object IO.MemoryStream @(,$Encrypted)
$cs = new-Object Security.Cryptography.CryptoStream $ms,$d,"Read"
$sr = new-Object IO.StreamReader $cs
Write-Output $sr.ReadToEnd()
$sr.Close()
$cs.Close()
$ms.Close()
$r.Clear()
}
コード内で SHA1 を参照する場所が 2 つあります。
SHA256 に切り替えたいのですが、上記の .NET クラスの両方が SHA256 をサポートしていますが、次のエラーがスローされます。太字のテキストを SHA1 から SHA256 に変更します
Exception calling "ReadToEnd" with "0" argument(s): "Padding is invalid and cannot be removed."
At J:\UTemp\063146ee-175d-4a33-b485-7c6dd0e309f6.ps1:28 char:5
+ Write-Output $sr.ReadToEnd()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CryptographicException
Exception calling "Close" with "0" argument(s): "Padding is invalid and cannot be removed."
At J:\UTemp\063146ee-175d-4a33-b485-7c6dd0e309f6.ps1:29 char:5
+ $sr.Close()
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CryptographicException
どんな支援も大歓迎 アーニー