Languages

Java - how to write own custom base64 util?

5 points
Asked by:
JustMike
3518

Can someone help me to write custom base64 util in java?

Two basic methods:

  • encode string
  • decode string

Without using internal java core methods or external library like apache.

It should be as simple as possible. I would like to learn how to build simple base64.

Thank you.

1 answers
2 points
Answered by:
JustMike
3518

Check this article: https://dirask.com/posts/p59Jnp

Code from the article:

import java.util.Base64;

public class Example {

    public static void main(String[] args) {

        String text = "test123";

        // encode
        String encodedString = Base64.getEncoder().encodeToString(text.getBytes());
        System.out.println(encodedString); // dGVzdDEyMw==

        // decode
        String decodedString = new String(Base64.getDecoder().decode(encodedString));
        System.out.println(decodedString); // test123
    }
}

 

0 comments Add comment
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.