Skip to content

Instantly share code, notes, and snippets.

@darkoperator
Created March 4, 2014 15:32
Show Gist options
  • Select an option

  • Save darkoperator/9348627 to your computer and use it in GitHub Desktop.

Select an option

Save darkoperator/9348627 to your computer and use it in GitHub Desktop.
function Import-ShodanAPIKey
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[securestring]$MasterPassword
)
Begin
{
# Test if configuration file exists.
if (!(Test-Path "$($env:AppData)\Posh-Shodan\api.key"))
{
throw "Configuration has not been set, Set-ShodanAPIKey to configure the API Keys."
}
}
Process
{
$ConfigFileContent = Get-Content -Path "$($env:AppData)\Posh-Shodan\api.key"
$SecString = ConvertTo-SecureString -SecureKey $MasterPassword $ConfigFileContent
$APIKey = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecString))
$Global:ShodanAPIKey = $APIKey
}
End
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment