Showing posts with label base64 encode. Show all posts
Showing posts with label base64 encode. Show all posts

Friday, July 28, 2017

How to encode BASE64 via MySQL | MySQL from BASE64 | BASE64 ENCODE AND DECODE IN MySQL | BASE64 encode in MySQL

How to encode BASE64 via MySQL | MySQL from BASE64 | BASE64 ENCODE AND DECODE IN MySQL | BASE64 encode in MySQL

I want to select a blob col from one table, BASE64 encode it and insert it into another tables. Is there any way to do this without round tripping the data out of the DB and through my app?

I was looking for the same thing and I've just seen that MySQL 5.6 has a couple of new string functions supporting this functionality: TO_BASE64 and FROM_BASE64.

SELECT FROM_BASE64('YmFzZTY0IGVuY29kZWQgc3RyaW5n');


SELECT TO_BASE64(field_name) FROM table_name;

Thursday, December 12, 2013

Base64 encode/decode with JAVA

Java code to encode and decode base64


package pritom;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * Created with IntelliJ IDEA.
 * User: pritom
 * Date: 12/12/13
 * Time: 10:41 AM
 * To change this template use File | Settings | File Templates.
 */
public class EncodeDecodeBase64 {
    public static void main(String[] args) throws Exception{
        String baseString = "TESTING BASE 64 ENCODING AND DECODING WITH JAVA";
        System.out.println("Base string:     " + baseString);

        /**
         * Encoding to base 64
         */
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String encodedString = base64Encoder.encodeBuffer(baseString.getBytes());
        System.out.print("Encoded base 64: " + encodedString);

        /**
         * Decoding from base 64
         */
        BASE64Decoder base64Decoder = new BASE64Decoder();
        String decodedString = new String(base64Decoder.decodeBuffer(encodedString), "UTF-8");
        System.out.println("Decoded base 64: " + decodedString);
    }
}

Output


Base string:     TESTING BASE 64 ENCODING AND DECODING WITH JAVA
Encoded base 64: VEVTVElORyBCQVNFIDY0IEVOQ09ESU5HIEFORCBERUNPRElORyBXSVRIIEpBVkE=
Decoded base 64: TESTING BASE 64 ENCODING AND DECODING WITH JAVA