Powershell date type unable to find

六眼飞鱼酱① 提交于 2021-01-28 06:09:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!