我正在尝试解密 PowerShell“7.x”中的文件。我明确使用
Unprotect-PGP
cmdlet,但我收到的错误消息是指 Protect-PGP
cmdlet。我唯一能想到的可能是版本冲突,但我真的不确定......非常感谢任何帮助或绝妙的想法(即使是半绝妙的也可以)!!
发表声明:
BouncyCastle.Crypto
抛出错误:
Unprotect-PGP -FilePathPrivate "G:\TEMP\secretkey.asc" -Password "XXXXXXXXX" -FolderPath "G:\TEMP\ABM\PROD_Test.csv.pgp" -OutputFolderPath "G:\TEMP\"
组装安装:
WARNING: Protect-PGP - Can't encrypt files because: Exception calling ".ctor" with "2" argument(s): "Could not load file or assembly 'BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942'. Could not find or load a specific file. (0x80131621)"
PS C:\> # List Bouncy Castle version currently loaded
>> $assemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()
>> $bouncyCastle = $assemblies | Where-Object { $_.ManifestModule.Name -eq "BouncyCastle.Crypto.dll" }
>> $bouncyCastleVersion = $bouncyCastle.GetName().Version
>> $bouncyCastleVersion
Major Minor Build Revision
----- ----- ----- --------
1 8 8 0
开关:
-NoProfile
重新启动 PowerShell,然后再次运行 cmdlet,看看是否仍然失败。如果它没有失败,那么您可以假设有一些其他模块使用同一程序集的旧版本导致此问题,可能的解决方案是升级所述模块,假设它确实使用较新版本的程序集。抛开这一点,您在使用输入和输出文件时似乎有一个拼写错误,当您应该用于解密文件的参数是 pwsh -NoProfile
和
-FolderPath
时,您正在使用 -OutputFolderPath
和 -FilePath
.假设程序集的用法没有改变的另一种解决方法是使用您已经直接加载的-OutFilePath
程序集而不是
BouncyCastle.Crypto
:Unprotect-PGP