Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the Base64Encoder class?

Hi I saw an example on StackOverflow which had this code:

String encoding = Base64Encoder.encode ("test1:test1");
HttpPost httppost = new HttpPost("http://host:post/test/login");
httppost.setHeader("Authorization", "Basic " + encoding);

System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

I have a task similar to this. I tried to use the same code but I couldn't find the Base64Encoder class anywhere. Im using httpclient-4.1.2.jar and httpcore-4.1.2.jar. Can someone help me with this?

like image 757
Geek Avatar asked Jan 06 '12 17:01

Geek


People also ask

What is base64encoder?

Base64 is a binary-to-text encoding scheme. It represents binary data in a printable ASCII string format by translating it into a radix-64 representation.

What is Base64 class in Java?

Java 8 introduced the Base64 class, which is available in the java. util. Base64. The Base 64 is a strategy or scheme to encode the binary data into encoded text format, which can be easily sent over the internet without corrupted and data loss with securely.

What is import Java Util Base64?

You can encrypt and decrypt your data by using provided methods. You need to import java. util. Base64 in your source file to use its methods. This class provides three different encoders and decoders to encrypt information at each level.

Is Java Base64 encoder thread safe?

Instances of Base64. Encoder class are safe for use by multiple concurrent threads. Unless otherwise noted, passing a null argument to a method of this class will cause a NullPointerException to be thrown.


1 Answers

A Base64 en/decoder has long been missing from the Java APIs, so you'll have to find a good 3rd party one, e.g. Apache Commons Codec, iHarder Base64, etc.

like image 84
maerics Avatar answered Oct 10 '22 22:10

maerics