how to convert hex string into base64 ? I found this page http://home2.paulschou.net/tools/xlate/ but I need some function in java: String base64 = ...decoder(String hex);
I found something in the Internet but they are to difficult and use byte array. I am looking for something simplier
thx a lot
The difference between Base64 and hex is really just how bytes are represented. Hex is another way of saying "Base16". Hex will take two characters for each byte - Base64 takes 4 characters for every 3 bytes, so it's more efficient than hex.
How it works. Base64 encoding takes the original binary data and operates on it by dividing it into tokens of three bytes. A byte consists of eight bits, so Base64 takes 24bits in total. These 3 bytes are then converted into four printable characters from the ASCII standard.
Convert Files to Base64Just select your file or drag & drop it below, press the Convert to Base64 button, and you'll get a base64 string. Press a button – get base64. No ads, nonsense, or garbage. The input file can also be an mp3 or mp4.
Have a look at Commons Codec :
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
byte[] decodedHex = Hex.decodeHex(hex);
byte[] encodedHexB64 = Base64.encodeBase64(decodedHex);
You are not likely to find something that converts directly from hex to base-64. You'll need to find or write a hex decoder and a base-64 encoder, and use a byte[]
as an intermediate form.
Compare reality with what you are asking for:
String b64 = encoder.encode(decoder.decode(hex)); /* Too difficult :( !!! */
versus
String b64 = transcoder.transcode(hex); /* So much simpler! */
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