none
How to encrypt a text string and then decrypt it? RRS feed

  • Question

  • OK, I understand that I can convert text into a secure string doing something like this:

    $text_secure = convertto-securestring -asplaintext -force $text_unsecure

    Then I can convert the secure string into an encrypted secure string like this:

    $text_secure_encrypted = convertfrom-securestring $text_secure

    And I can write this out to a file to store $text_unsecure as an encrypted value.

    How do I get $text_secure_encrypted back to its original form?

    I assume I first convert it to a secure string:

    $text_secure = convertto-securestring $text_secure_encrypted

    But how to I convert it from a secure string back to plain text after that?

    Thanks,

    Steve

    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:49 PM Question outside forum scope (nice try, though)
    Thursday, August 3, 2017 8:33 PM

All replies

  • help ConvertFrom-SecureString -full

    Look at the examples.


    \_(ツ)_/

    Thursday, August 3, 2017 8:41 PM
  • Here it goes:

    $string = "Classified Information"

    #Encrypt
    $Encrypted = ConvertTo-SecureString -AsPlainText $string -Force
    $Encrypted

    #Decrypt
    $Temp = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($Encrypted)
    $Decrypted = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Temp)
    [System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Temp)
    $Decrypted



    Rafael Carneiro Machado (https://www.linkedin.com/in/rafaelcarneiromachado/)

    Friday, August 4, 2017 8:44 AM