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?
PowerShell Base64 is a technique or mechanism that is used to encode and decode data. The encoding and decoding are important in order to prevent the data from malware attacks. Base64 encoding and decoding is a popular method to encrypt and decrypt the data.
Artjom B. Base64 is not encryption. But yes, different input strings will always encode to different Base64-encoded strings, and the same input string will always encode to the same Base64-encoded string. It's not a hash though, so small changes in the input will only result in small changes in the output.
From Wikipedia: The final '==' sequence indicates that the last group contained only one byte, and '=' indicates that it contained two bytes.
Adding the comment from @Raziel as an answer for better discoverability of this question.
[System.Text.Encoding]::Unicode]
is UTF-16, the later is UTF-8. There's [System.Text.Encoding]::UTF8
that you can use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With