我想知道是否有人可以帮助我解决我在PowerShell中遇到的错误。我对创建如下所示的加密器没有任何问题:
$Crypto = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
$IV = New-Object System.Byte[] 16
$Crypto.GetNonZeroBytes($iv)
$RIJSym = new-Object System.Security.Cryptography.RijndaelManaged
[byte[]] $Key = ('mysecret$%@').ToCharArray()
$Encryptor = $RIJSym.CreateEncryptor($Key,$IV)
但是,当我想解密我的密钥时,出于什么原因我遇到了问题,这就是我正在使用的内容以及程序运行时出现的错误:
$Decrypted = $RIJSym.CreateDecryptor($Encryptor)
错误消息
Cannot find an overload for "CreateDecryptor" and the argument count: "1".
At line:15 char:1
+ $DeCryp = $rijSym.CreateDecryptor($encryptor)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
答案 0 :(得分:3)
错误说明了所有...... CreateDecryptor()
没有重载使用onl一个参数。有效的重载是:
PS > $RIJSym.CreateDecryptor
OverloadDefinitions
-------------------
System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
System.Security.Cryptography.ICryptoTransform CreateDecryptor()
您需要以与创建加密器相同的方式创建解密器:通过指定密钥和IV。实施例
$Decrypted = $RIJSym.CreateDecryptor($Key, $IV)