-2

I have a problem where json is encoded as base64 and I have to read that base64 and decode it and use the values of json.

My Json Structure:

{
  "name" : "myname",
  "id" : "1234568",
  "class" : "science"
}

My Base64:

ewogICJuYW1lIiA6ICJteW5hbWUiLAogICJpZCIgOiAiMTIzNDU2OCIsCiAgImNsYXNzIiA6ICJzY2llbmNlIgp9

How can I decode this and get the values of the class?

Ethan
  • 876
  • 8
  • 18
  • 34
  • What are you having trouble with exactly? – tgdavies Dec 23 '20 at 04:33
  • There are plenty of libraries that will do this. What programming language are you using? Also, make sure to know if this is base64 url encoded or not. – Swan Toma Dec 23 '20 at 04:36
  • I want to know how we decode it in Java – Swaroopa Nalla Dec 23 '20 at 04:36
  • Maybe an example like this helps: https://www.tutorialspoint.com/java8/java8_base64.htm – Swan Toma Dec 23 '20 at 04:40
  • 1
    *I'm curious:* In what way did a **web search** for [`java decode base64`](https://www.google.com/search?q=java+decode+base64) fail to give you an answer? --- Question down-voted because it "does not show any research effort". – Andreas Dec 23 '20 at 05:31

1 Answers1

1

If you still need help, you can try this:

import java.util.Base64;

public class Tmp {

    public static void main(String [] args){
        byte[] base64decodedBytes = Base64.getDecoder().decode("ewogICJuYW1lIiA6ICJteW5hbWUiLAogICJpZCIgOiAiMTIzNDU2OCIsCiAgImNsYXNzIiA6ICJzY2llbmNlIgp9");
        String original = new String(base64decodedBytes);
        System.out.println("Original String: " + original);
    }
}
Swan Toma
  • 136
  • 6