问题
I am trying to use PowerShell to connect virustotal API, the code is from virustotal website and I got "Unable to find type [System.Security.Cryptography.ProtectedData]." error message.
The code as follow
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!"
}
}
after research I find I need to use add-type to add something to solve this. Any suggestion what I need to add? Thanks in advance.
回答1:
The MSDN documentation page lists the assembly as System.Security. So you need to:
Add-Type -AssemblyName System.Security
You may also want to consider System.Core for some of the other Cryptography features (google search lists them)
Add-Type -AssemblyName System.Core
来源:https://stackoverflow.com/questions/48797700/powershell-date-type-unable-to-find