Last active
January 3, 2018 18:11
-
-
Save tylerapplebaum/97f3193370a857c3725264b1faacafda to your computer and use it in GitHub Desktop.
A function to convert a string to base64 encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Convert-ToBase64 { | |
param( | |
[CmdletBinding()] | |
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="String to encode to base64")] | |
[ValidateNotNullOrEmpty()] | |
$String | |
) | |
$StringToByteArr = [System.Text.Encoding]::UTF8.GetBytes($String) #Converts string to byte array | |
$Base64String = [System.Convert]::ToBase64String($StringToByteArr) #Converts byte array to b64 string | |
Return $Base64String | |
$Base64ToUTF8 = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Base64String)) #Converts b64 string to UTF-8 string | |
} #End Convert-ToBase64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment