I use powershell to convert string
$Text = 'ouser:v3$34@#85b&g%fD79a3nf'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText
However when using https://www.base64decode.org/, or some java libraries for base64 encoding I get a different, shorter version.
Sample string:
This is a secret and should be hiden
powershell result:
VABoAGkAcwAgAGkAcwAgAGEAIABzAGUAYwByAGUAdAAgAGEAbgBkACAAcwBoAG8AdQBsAGQAIABiAGUAIABoAGkAZABlAG4A
normal base64 result:
VGhpcyBpcyBhIHNlY3JldCBhbmQgc2hvdWxkIGJlIGhpZGVu
While using the website I am able to decode both versions, however using my java code I am only able to decode the latter. Why is that? Is there more than one version of base64? Where those differences come from?
[System.Text.Encoding]::Unicode
is UTF-16, the latter is UTF-8. There's[System.Text.Encoding]::UTF8
that you can use.