ตัวอย่าง Java Base64 Encoding and Decoding




ตัวอย่าง Java Code ในการทำ Encode และ Decode 
ด้วย Base64 เป็นการ Encode อย่างง่ายสุดนะครับ
สำหรับข้อมูลที่ไม่ได้ต้องการปิดบังหรือ Privacy มาก
เพราะว่า สามารถ Decode กลับมาเป็นข้อมูลจริง ได้ง่ายมากๆ

import org.apache.commons.codec.binary.Base64;

public class TestEncode {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String input="data_for_encode";
        byte[] bytes = Base64.encodeBase64(input.getBytes());
        System.out.println("Encode " + new String(bytes));
        byte[] decodedBytes = Base64.decodeBase64(bytes);
        System.out.println("Decode " + new String(decodedBytes));

    }
}


ผลที่ได้จากการ Run ก็ตามรูปต้านล่างเลย

Encode ZGF0YV9mb3JfZW5jb2Rl
Decode data_for_encode 



ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

Oracle date format จัด format date ให้แสดง พศ และ เดือน ภาษาไทยหรือตามภาษาที่เราเลือก

java -Xms , java -Xmx กำหมด memory ให้ JVM เพื่อป้องกันปัญหา Out of Memory

Java this กับ super การใช้งานคำสั่ง this กับ super ใน ภาษา Java