How can I decode a base64 string from the command line?

To follow up on Starson's post, PHP was changed to no longer treat a space as if it were a plus sign in CVS revision, which corresponds to PHP 5.1.0. You can see what happened with a diff to branch point 1.43 at:

The CVS log indicates that this change was made to fix bug #34214 (base64_decode() does not properly ignore whitespace).

It would seem from the comment preceding the code which was removed that the treatment of the space as if it were the plus sign was actually intentional at one time:

When Base64 gets POSTed, all pluses are interpreted as spaces.
This line changes them back. It's not exactly the Base64 spec,
but it is completely compatible with it (the spec says that spaces
are invalid). This will also save many people considerable

if (ch == ' ') ch = '+';

However, RFC 3548 states that characters not in the Base64 alphabet should...

0 0
0 0

This form below allows you to decode Base64-encoded text strings. It s pretty simple to use - just paste in the Base64 text you want to decode and then press the Decode button.

Note: If the text string you are decoding results in a binary output, it will be sent directly back to your client as a stream allowing you to save it as its correct file type. Given the number of possible objects that you could be trying to decode (GIFs, sound files etc.), we re not going to try and produce a page that will format it all properly! Trying to output a sound file to an HTML stream wouldn t be that useful anyway...

If you don't want this binary behaviour, pressing Decode Safely As Text will try its best to output the decoded stream as text. This may result in gibberish, but it won't result in you being infected by a decoded virus. If you want to be extra, extra careful, you can use the Decode Safely As Text page which doesn't have the binary feature at...

0 0

To anyone who is still interested in this question: If: 1-decodeByteArray returns null 2-Base64.decode throws bad-base64 Exception

Here is the solution: -You should consider the value sent to you from API is Base64 Encoded and should be decoded first in order to cast it to a Bitmap object! -Take a look at your Base64 encoded String, If it starts with


The Base64.decode won't be able to decode it, So it has to be removed from your encoded String:

final String encodedString = "data:image/jpg;base64, ...."; final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",") + 1);

Now the pureBase64Encoded object is ready to be decoded:

final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);

Now just simply use the line below to turn this into a Bitmap Object! :

Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);

Or if...

0 0

OpenSSL Command-Line HOWTO

The openssl application that ships with the OpenSSL libraries can perform a wide range of crypto operations. This HOWTO provides some cookbook-style recipes for using it.

Paul Heinlein | February 24, 2016

The openssl command-line binary that ships with the OpenSSL libraries can perform a wide range of cryptographic operations. It can come in handy in scripts or for accomplishing one-time command-line tasks.

Documentation for using the openssl application is somewhat scattered, however, so this article aims to provide some practical examples of its use. I assume that you’ve already got a functional OpenSSL installation and that the openssl binary is in your shell’s PATH.

Just to be clear, this article is strictly practical; it does not concern cryptographic theory and concepts. If you don’t know what an MD5 sum is, this article won’t enlighten you one bit—but if all you need to know is how to use openssl to generate a...

0 0

Something Sun Should Have Included Long Ago

(And now has! As of Java v1.8, there is a Base64 class. Finally.)

Download now! (v2.3.7 48KB)

Follow the file release RSS feed...

This is a Public Domain Java class providing very fast Base64 encoding and decoding in the form of convenience methods and input/output streams.

There are other Base64 utilities on the Internet, some part of proprietary packages, some with various open source licenses. In any event, I hope with one or more of these Base64 tools, you won't have to write your own like I did.

If you use Maven, thank Owen O'Malley from Apache and Matthew from Sensible Development for working up a Base64 Maven Repository.

Thanks to Brian Burton for providing this test class for use with (The test file hasn't been updated in a while.)

You may view the Base64 javadoc API online, if you...

0 0

I found the base code for this here: If you want to know more about Base64, check out this
Wikipedia Entry

But I’m not a command-line guy, I’m a developer, and I like to have my code in a file where I can edit it, modify it, re-use it, and run it.

Function Base64Encode($textIn) { $b = [System.Text.Encoding]::UTF8.GetBytes("Hello World") $encoded = [System.Convert]::ToBase64String($b) return $encoded } Function Base64Decode($textBase64In) { $b = [System.Convert]::FromBase64String($textBase64In) $decoded = [System.Text.Encoding]::UTF8.GetString($b) return $decoded } #Test Logic $base64Encoded = Base64Encode("Hello World") Write-Host "`$base64Encoded=$base64Encoded" $base64Decoded = Base64Decode($base64Encoded) Write-Host "`$base64Decoded=$base64Decoded"

Here is the results of running the above code:

What is your password?: Hello World...
0 0