Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Last active March 17, 2023 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhunt/42dbe8de803e00b6b3d08435c26e725e to your computer and use it in GitHub Desktop.
Save cdhunt/42dbe8de803e00b6b3d08435c26e725e to your computer and use it in GitHub Desktop.
A PowerShell function to duplicated the Unix base64 util.
function Convert-Base64 {
[CmdletBinding()]
[Alias("base64")]
param (
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[string]
$InputObject,
[Parameter()]
[switch]
$Decode
)
process {
switch ($true) {
$Decode {
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($InputObject))
break;
}
Default {
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($InputObject))
}
}
}
}
@cdhunt
Copy link
Author

cdhunt commented Mar 17, 2023

Example

You can copy Linux sample code and run in PowerShell without any changes.

kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}' | base64 -d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment