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