我正在尝试使用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!"
}
}
经过研究,我发现我需要使用 add-type 来添加一些东西来解决这个问题。我需要添加什么建议吗?
提前致谢。
MSDN 文档页面 https://msdn.microsoft.com/en-us/library/system.security.cryptography.protecteddata(v=vs.110).aspx将程序集列为System.Security
。所以你需要:
Add-Type -AssemblyName System.Security
您可能还想考虑System.Core
对于一些其他密码学功能(谷歌搜索列出了它们 https://www.google.co.uk/search?q=system.core+cryptography)
Add-Type -AssemblyName System.Core
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)