Base64 Java encode and decode a string [duplicate]

You can use following approach: import org.apache.commons.codec.binary.Base64; // Encode data on your side using BASE64 byte[] bytesEncoded = Base64.encodeBase64(str.getBytes()); System.out.println(“encoded value is ” + new String(bytesEncoded)); // Decode data on other side, by processing encoded data byte[] valueDecoded = Base64.decodeBase64(bytesEncoded); System.out.println(“Decoded value is ” + new String(valueDecoded)); Hope this answers your doubt.

Strange \n in base64 encoded string in Ruby

Edit: Since I wrote this answer Base64.strict_encode64() was added, which does not add newlines. The docs are somewhat confusing, the b64encode method is supposed to add a newline for every 60th character, and the example for the encode64 method is actually using the b64encode method. It seems the pack(“m”) method for the Array class used … Read more

Encoding as Base64 in Java

You need to change the import of your class: import org.apache.commons.codec.binary.Base64; And then change your class to use the Base64 class. Here’s some example code: byte[] encodedBytes = Base64.encodeBase64(“Test”.getBytes()); System.out.println(“encodedBytes ” + new String(encodedBytes)); byte[] decodedBytes = Base64.decodeBase64(encodedBytes); System.out.println(“decodedBytes ” + new String(decodedBytes)); Then read why you shouldn’t use sun.* packages. Update (2016-12-16) You can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)