How to generate encoded base 64 string from string ?
When we work with REST API’s we have to deal with different authentications. One of the popular authentiation is from the given token string we need to generate the encoded base 64 string and need to pass as the additional authentication headers.
Table of Contents
Using Apache Commons (import org.apache.commons.codec.binary.Base64;)
String to Encoded Base 64 – Sample Code:
public static void main(String[] args) {
String auth = "ngdeveloper-token-string";
byte[] encodedAuth =
Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
String encodedAuthString = new String(encodedAuth);
System.out.println(encodedAuthString);
}
Using Java Inbuilt Base 64
String to Encoded Base 64 – Sample Code:
public static void main(String[] args) {
String auth = "ngdeveloper-token-string";
String encodedAuth =
Base64.getEncoder().encodeToString(auth.getBytes());
System.out.println(encodedAuth);
}
Output:
you will get encoded base 64 string something like,
bmdkZXZlbG9wZXItdG9rZW4tc3RyaW5n
I am bit confused about Idempotent methods in REST API and how is it relevant in RESTful web services domain?
Real Estate I very delighted to find this internet site on bing, just what I was searching for as well saved to fav
Techno rozen You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
Simplywall There is definately a lot to find out about this subject. I like all the points you made
Strands Hint Nice post. I learn something totally new and challenging on websites
Houzzmagazine This was beautiful Admin. Thank you for your reflections.