none
How to encrypt password using provided pgp public key in Powershell? RRS feed

  • Question

  • I have a PGP public key that is used to encrypt passwords. Using Powershell, how do I encrypt a password using a pgp public key; which then I will use to update the credentials in  a text file ?

    This is what I  have tried:

    $Keyfile= "C:\PKey\PubKey.pub"
    $Key = Get-Content $Keyfile

    "P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Securekey $Key 

    But i get the output "Cannot convert the value of type "System.String" to "System.Security.SecureString"

    Appreciate your help!

    Thursday, January 11, 2018 9:32 PM

Answers

  • The question was about how to securely store a password. You can use DPAPI (no -Key or -SecureKey parameter to ConvertFrom-SecureString and ConvertTo-SecureString - can only decrypt on same computer with same user account), or you can use AES (requires use of -Key or -SecureKey parameter). Export-CliXml and Import-CliXml technique on PowerShell 3.0 and later uses DPAPI (it has no -Key or -SecureKey parameters).


    -- Bill Stewart [Bill_Stewart]

    Friday, January 12, 2018 11:10 PM
    Moderator

All replies