Java Encryption Series (II) BASE64 encryption

Source: Internet
Author: User

Sun.misc. Base64encoder The /base64decoder class is not part of the JDK standard library category, but it is included in the JDK and can be used directly, but this does not have Java doc, which is not a recommended tool class in the JDK. It is highly recommended not to use Sun.misc, which is not safe.

Bouncycastle jar Package:http://www.bouncycastle.org/latest_releases.html


Package Com.tvm.mrz.security.base64;import Java.io.ioexception;import org.apache.commons.codec.binary.Base64; Import Sun.misc.base64decoder;import Sun.misc.base64encoder;public class Base64test {private static String src = "Mr.Z Se Curity Base64 ";p ublic static void JdkBase64 () {Base64encoder encoder = new Base64encoder (); String encode = Encoder.encode (Src.getbytes ()); System.out.println ("Encode:" + encode); Base64decoder decoder = new Base64decoder (); try {byte[] decode = decoder.decodebuffer (encode); System.out.println ("Decode:" + new String (decode));} catch (IOException e) {e.printstacktrace ();}} public static void CommonsCodecBase64 () {//String encode = base64.encodebase64string (Src.getbytes ()); byte[] encode = Ba Se64.encodebase64 (Src.getbytes ()); System.out.println ("Encode:" + new String (encode)); byte[] decode = base64.decodebase64 (encode); System.out.println ("Decode:" + new String (decode));} public static void BouncyCastleBase64 () {byte[] encode = org.bouncycastle.uTil.encoders.Base64.encode (Src.getbytes ()); System.out.println ("Encode:" + new String (encode)); byte[] decode = Org.bouncycastle.util.encoders.Base64.decode (Enco DE); System.out.println ("Decode:" + new String (decode));} public static void Main (string[] args) {jdkBase64 (); CommonsCodecBase64 (); BouncyCastleBase64 ();}}


Java Encryption Series (II) BASE64 encryption

Related Article

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.