Java Writing Base64 cipher

Source: Internet
Author: User
Tags base64 gettext

BASE64 encryption algorithm, widely used, especially in e-mail transmission, has a great use

The program code written in Java is as follows

Importjava.awt.BorderLayout;ImportJava.awt.EventQueue;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;Importjava.io.IOException;ImportJavax.swing.JFrame;ImportJavax.swing.JPanel;ImportJavax.swing.border.EmptyBorder;ImportJavax.swing.JTextArea;ImportJavax.swing.JButton; Public classBase64frameextendsJFrame {PrivateJPanel ContentPane; PrivateJButton Btnnewbutton; PrivateJTextArea TextArea; PrivateJButton btnnewbutton_1; PrivateJTextArea textarea_1; /*** Launch the application. */     Public Static voidMain (string[] args) {Eventqueue.invokelater (NewRunnable () { Public voidrun () {Try{base64frame frame=NewBase64frame (); Frame.setvisible (true); } Catch(Exception e) {e.printstacktrace ();    }            }        }); }    /*** Create the frame. */     PublicBase64frame () {Settitle ("Base64 cipher"); Setresizable (false);        Setdefaultcloseoperation (Jframe.exit_on_close); SetBounds (100, 100, 505, 405); ContentPane=NewJPanel (); Contentpane.setborder (NewEmptyborder (5, 5, 5, 5));        Setcontentpane (ContentPane); Contentpane.setlayout (NULL); TextArea=NewJTextArea (); Textarea.setbounds (14, 13, 471, 136);                Contentpane.add (TextArea); Textarea_1=NewJTextArea (); Textarea_1.setbounds (14, 206, 471, 151);                Contentpane.add (textarea_1); Btnnewbutton=NewJButton ("Encoding"); Btnnewbutton.setbounds (14, 166, 113, 27);                Contentpane.add (Btnnewbutton); Btnnewbutton_1=NewJButton ("Decode"); Btnnewbutton_1.setbounds (372, 162, 113, 27);        Contentpane.add (btnnewbutton_1); Btnnewbutton.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {textarea_1.settext (Base64util.encryptbase64 (Textarea.gettext (). GetByt                            ES ()));        }        }); Btnnewbutton_1.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {Try{textarea_1.settext (Base64util.decryptbase64 (Textarea.gettext ())); } Catch(IOException E1) {//TODO auto-generated Catch blockE1.printstacktrace ();    }                            }        }); }}
Importjava.io.IOException;ImportDecoder.base64decoder;ImportDecoder.base64encoder; Public classBase64util { Public StaticString EncryptBase64 (byte[] data) {        return NewBase64encoder (). Encode (data);//Coding Algorithm    }         Public StaticString decryptBase64 (String data)throwsioexception{byte[] Resultbytes =NewBase64decoder (). Decodebuffer (data);//data on behalf of ciphertext        return NewString (resultbytes);//returns the string form of a byte array    }}

The Base64util tool class is provided by the Geek College;

This requires support for the Sun.misc.BASE64Decode.jar JDK Development Kit, which can be downloaded from the JDK's website or by clicking this link.

http://yunpan.cn/c3XmzH5Tmcg6b Access Password f450

Java Writing Base64 cipher

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.