PowerShell: Decrypt a Secure String

In this blog post I will carry out how to decrypt a secure string. A secure string is a string that is saved in a non-readable format to temporarily store passwords and strings. Let’s start.

For testing purposes, store a password as a secure string.

$password = ConvertTo-SecureString 'P@ssw0rd' -AsPlainText -Force

Next, we will use a somewhat cryptic code to decrypt this.

$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($password)
$result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)

Here is the entire code in action:

Fine that’s it.

Categories: PowerShell

Tagged as: , ,

2 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.