"Java" (1) BASE64 encryption technology

Source: Internet
Author: User
Tags base64

1. JDK

/** * Use JDK to implement Base64 encryption */public static void JdkBase64 () {try {Base64encoder encoder = new Base64encoder (); String encode = Encoder.encode (Src.getbytes ()); System.out.println ("Encode:" + encode); Base64decoder decoder = new Base64decoder (); System.out.println ("Decode:" + New String (Decoder.decodebuffer (encode));} catch (IOException e) {e.printstacktrace ();}}

In the case of using this method, there may be a situation where base64encoder cannot be found, which resolves:

Right-click Project--Properties-->java build Path-->libraries-->jre System library-->access rules-->edit-->add--> Resolution Select Accessible,rule pattern to fill in the **-->ok.


2. Commons Codec

/** * Use Commonscodes to implement Base64 encryption */public static void CommonsCodesBase64 () {byte[] encodebytes = base64.encodebase64 ( Src.getbytes ()); System.out.println ("Encode:" + new String (encodebytes)); byte[] decodebytes = base64.decodebase64 (encodebytes); System.out.println ("Decode:" + new String (decodebytes));}

3. Bouncy Castle

/** * Use Bouncycastle to implement Base64 encryption */public static void BouncyCastleBase64 () {byte[] encodebytes = Org.bouncycastle.util.encoders.Base64.encode (Src.getbytes ()); System.out.println ("Encode:" + new String (encodebytes)); byte[] Decodebytes = Org.bouncycastle.util.encoders.Base64.decode (encodebytes); System.out.println ("Decode:" + new String (decodebytes));}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Java" (1) BASE64 encryption technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.