我正在尝试使用 PowerShell 连接virustotal API,代码来自virustotal 网站,我得到“无法找到类型 [System.Security.Cryptography.ProtectedData]”。错误信息。
代码如下
function Get-VTApiKey {
[CmdletBinding()]
Param([String] $vtFileLocation = $(Join-Path $env:APPDATA 'virustotal.bin'))
if (Test-Path $vtfileLocation) {
$protected = [System.IO.File]::ReadAllBytes($vtfileLocation)
$rawKey = [System.Security.Cryptography.ProtectedData]::Unprotect($protected, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
return [System.Text.Encoding]::Unicode.GetString($rawKey)
} else {
throw "Call Set-VTApiKey first!"
}
}
Run Code Online (Sandbox Code Playgroud)
经过研究,我发现我需要使用 add-type 添加一些东西来解决这个问题。我需要添加什么建议?提前致谢。
MSDN 文档页面将程序集列为System.Security
. 所以你需要:
Add-Type -AssemblyName System.Security
Run Code Online (Sandbox Code Playgroud)
您可能还需要考虑System.Core
其他一些密码学功能(谷歌搜索列出了它们)
Add-Type -AssemblyName System.Core
Run Code Online (Sandbox Code Playgroud)