how to convert hex to base64

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);

Java Encode file to Base64 string To match with other encoded string

You already using apache commons-codec so I recommend adding commons-io for reading the file. That way you can remove your loadFile() method and just have: private static String encodeFileToBase64Binary(String fileName) throws IOException { File file = new File(fileName); byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(file)); return new String(encoded, StandardCharsets.US_ASCII); }

Convert byte[] to Base64 string for data URI

I used this and it worked fine (contrary to the accepted answer, which uses a format not recommended for this scenario): StringBuilder sb = new StringBuilder(); sb.append(“data:image/png;base64,”); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(imageByteArray, false))); contourChart = sb.toString();

Convert UTF-8 to base64 string

It’s a little difficult to tell what you’re trying to achieve, but assuming you’re trying to get a Base64 string that when decoded is abcdef==, the following should work: byte[] bytes = Encoding.UTF8.GetBytes(“abcdef==”); string base64 = Convert.ToBase64String(bytes); Console.WriteLine(base64); This will output: YWJjZGVmPT0= which is abcdef== encoded in Base64. Edit: To decode a Base64 string, simply … Read more

Decoding base64 from POST to use in PIL

You should try something like: from PIL import Image from io import BytesIO import base64 data[‘img’] = ”’R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLl N48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==”’ im = Image.open(BytesIO(base64.b64decode(data[‘img’]))) Your data[‘img’] string should not include the HTML tags or the parameters data:image/jpeg;base64 that are in the example JSFiddle. I’ve changed the image string for an example I took from Google, just for … Read more