r/PowerShell • u/gblang • Nov 13 '25
Question Encrypting and decrypting a string with Powershell using a text password
Hi all,
what is the best way to perform password based encryption and decryption with Powershell?
Here's some context:
I have a powershell utility script that performs some API call to a server. These calls include a token, which at the moment is for convenience stored in plaintext inside the script. Since I need to share this script with other possibly untrusted users, I would like to store this token encrypted, so that the user launching the script needs to insert the right key (password) to decrypt the token and successfully execute the API calls.
In short, I would like to:
- Take a plaintext string and encrypt it using a text password
- Make the inverse operation
- All of this using only Powershell v 5.1
I think it shouldn't be hard to do it, but I couldn't find a way on my own looking on the web, can anyone help me with this? Does it even make sense or is there a better way to obfuscate the token and request authorization for launching the script?
Much appreciate anyone taking the time!
View all comments
Show parent comment
2
u/gblang Nov 14 '25
Well, not only that, but also preventing them to do what the script was intended to do in the first place. Let's say that for me at the moment, it's enough to know that if the user knows the right password, then I trust he/she will not fiddle with the script to do anything bad :) but I agree with you that the token is not safe from anauthorized disclosure this way. It is just to get a bit of control on who can access to the token, indirectly and/or directly if he knows a bit of Powershell