Languages

Java - how to write own custom base64 util?

5 points
Asked by:
isherwood
239

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 answer
2 points
Answered by:
isherwood
239

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
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join