Private/ConvertTo-Base64Url.ps1
|
function ConvertTo-Base64Url { <# .SYNOPSIS Encodes bytes as base64url without padding, the encoding of the parts of a JSON Web Token. .EXAMPLE ConvertTo-Base64Url -Bytes ([System.Text.Encoding]::UTF8.GetBytes('{"alg":"HS256"}')) Returns eyJhbGciOiJIUzI1NiJ9. #> [CmdletBinding()] [OutputType([string])] param( # The bytes to encode. [Parameter(Mandatory)] [byte[]] $Bytes ) [System.Convert]::ToBase64String($Bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_') } |