How to convert string to Base64 and vice versa using Powershell

River Yang
Feb 24, 2017 · 1 min read

Working with Consul without UI is the correct way to go, which also help you with the productivity!!! (True?, hahaha~~)

Anyway, I’m not allowed to have a UI for it, come down to have read the correct value and make sure it’s the one we want it to be in there, I need to do heaps “Get” to get the value, however the value is encoded with Base64…

Here is the way to decode it:

$response = Invoke-RestMethod -Method Get -Uri "http://localhost:8500/v1/kv/hello"
$b = [System.Convert]::FromBase64String($($response.Value))
[System.Text.Encoding]::UTF8.GetString($b)
Hello World

To encode it:

$b  = [System.Text.Encoding]::UTF8.GetBytes("Hello World")
[System.Convert]::ToBase64String($b)
SGVsbG8gV29ybGQ=

Have fun~

River Yang

Things I learnt, I’m learning and tricks you cannot find from Official Documents

River Yang
River Yang
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade