Skip to content

Instantly share code, notes, and snippets.

@gravejester
Created April 5, 2015 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravejester/0dd28309b7a37af7aaf5 to your computer and use it in GitHub Desktop.
Save gravejester/0dd28309b7a37af7aaf5 to your computer and use it in GitHub Desktop.
function Invoke-Base64UrlDecode {
<#
.SYNOPSIS
.DESCRIPTION
.NOTES
http://blog.securevideo.com/2013/06/04/implementing-json-web-tokens-in-net-with-a-base-64-url-encoded-key/
Author: Øyvind Kallstad
Date: 23.03.2015
Version: 1.0
#>
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory)]
[string] $Argument
)
$Argument = $Argument.Replace('-', '+')
$Argument = $Argument.Replace('_', '/')
switch($Argument.Length % 4) {
0 {break}
2 {$Argument += '=='; break}
3 {$Argument += '='; break}
DEFAULT {Write-Warning 'Illegal base64 string!'}
}
Write-Output $Argument
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment