I am using ldap, working on java,there the password value is a base64 format, how to convert my normal text password sarath_dev to Base64 for Ldap?
-
3can you show some code of what you've tried so far? – Aurelio May 30 '15 at 12:22
-
what do you mean by code? i just want to enter base64 format password in ldap browser....thats all! – venkateswarlu valluri May 30 '15 at 12:26
-
you wanna encode your password in base64?? – Saket Mittal May 30 '15 at 12:38
-
but online emcoders are not proper...... – venkateswarlu valluri May 30 '15 at 12:41
-
I'm voting to close this question as off-topic because it is not a question about programming or about tools that are used primarily for programming. – RealSkeptic May 30 '15 at 12:44
-
Why convert to base64 for LDAP? LDAP does not require the password be in base64 format. – jwilleke May 31 '15 at 20:28
1 Answers
For those who are not familiar with base64 encoding
algorithm here is basic introduction. Base64 encodes (changes content of original String) String using an algorithm which uses 64 printable characters to replace each character in original string in an algorithmic sequence so that it can be decoded later. Base64 encoding prevents misuse of data by encoding it into ASCII format. Though there are more advanced encryption algorithm available like RSA-SHA
and MD5
and you should use those in production but base64
is real simple and easy to use for simple encoding needs.
Encoding & Decoding String into Base64 In Java
Here is a quick example of encoding and decoding of String in base64 encoding
algorithm. we will first encode String by converting it into byte array and than passing down to Base64.encodeBase64(byte[])
which encodes byte array
as per base64 encoding
algorithm and returns and encoded byte array, which can be converted into String. in Later half we will decode the String by calling Base64.decodeBase64(byte[])
method.
import org.apache.commons.codec.binary.Base64;
public class Base64EncodingExample{
public static void main(String args[]) throws IOException {
String orig = "original String before base64 encoding in Java";
//encoding byte array into base 64
byte[] encoded = Base64.encodeBase64(orig.getBytes());
System.out.println("Original String: " + orig );
System.out.println("Base64 Encoded String : " + new String(encoded));
//decoding byte array into base64
byte[] decoded = Base64.decodeBase64(encoded);
System.out.println("Base 64 Decoded String : " + new String(decoded));
}
}
Output:
Original String: original String before base64 encoding in Java
Base64 Encoded String : b3JpZ2luYWwgU3RyaW5nIGJlZm9yZSBiYXNlNjQgZW5jb2RpbmcgaW4gSmF2YQ==
Base 64 Decoded String : original String before base64 encoding in Java

- 3,726
- 3
- 29
- 49