Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hashtable to base64 conversation in powershell

I’m looking for a way out for converting hashtable to base64 in powershell. Not sure that’s possible or not. Can anyone help me on this?

Strings can be converted to base64 via byte. I’m seeing only string conversion examples.

Please help me to figure this out to proceed further.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks.

>Solution :

Convert the hash to JSON. Convert the JSON to Base64.

$hash = @{key = "value"}

# encode
$json = $hash | ConvertTo-JSON -Depth 100 -Compress
$bytes = [System.Text.Encoding]::UTF8.GetBytes($json)
$b64 = [System.Convert]::ToBase64String($bytes)   # => 'eyJrZXkiOiJ2YWx1ZSJ9'

# decode
$bytes = [System.Convert]::FromBase64String($b64)
$json = [System.Text.Encoding]::UTF8.GetString($bytes)
$hash = $json | ConvertFrom-Json
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading