JQuery implements base64 foreground encryption and decryption, and jquerybase64
This example describes how jQuery implements base64 foreground encryption and decryption. We will share this with you for your reference. The details are as follows:
Many people think of encodeURI and escape for encryption. This is useful for encrypted URLs, especially URLs with Chinese parameters.
If you only want to perform encryption and decryption, similar to Java's DES, jQuery has jquery. base64.js on the Internet.
(For md5 encryption of js, you can use jquery. md5.js. If you are interested, try it ).
The following is a test:
<Html>
Is encryption and decryption in the background the same as that in the foreground?
Let's test:
Package com. code; import sun. misc. BASE64Decoder; import sun. misc. BASE64Encoder; /*** Base64 encryption -- decryption ** @ author lushuaiyin **/public class Base64Util {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub String str = "suolong2014version"; System. out. println ("test plaintext [" + str + "]"); String basecode = Base64Util. encodeBase64 (str); System. out. println ("encrypted [" + basecode +"] "); If (basecode! = Null) {String res = Base64Util. decodeBase64 (basecode); System. out. println ("decrypted [" + res + "]");} //////////////////////////////////////// /System. out. println (""); System. out. println ("N Encryption tests --------"); String basecodeN = Base64Util. encodeBase64 (str, 2); String resN = Base64Util. decodeBase64 (basecodeN, 2); String basecodeN3 = Base64Util. encodeBase64 (str, 5); String resN3 = Base64Util. decodeBase64 (basecodeN3, 5 );} // Provide encryption for N times public static String encodeBase64 (String mingwen, int times) {int num = (times <= 0 )? 1: times; String code = ""; if (mingwen = null | mingwen. equals ("") {} else {code = mingwen; for (int I = 0; I <num; I ++) {code = encodeBase64 (code);} System. out. println ("encrypted" + num + "times later [" + code + "]");} return code ;} // The corresponding public static String decodeBase64 (String mi, int times) {int num = (times <= 0 )? 1: times; String mingwen = ""; if (mi = null | mi. equals ("") {} else {mingwen = mi; for (int I = 0; I <num; I ++) {mingwen = decodeBase64 (mingwen);} System. out. println ("decrypted" + num + "times later [" + mingwen + "]");} return mingwen ;} //////////////////////////////////////// /// // public static String encodeBase64 (String mingwen) {String code = ""; if (mingwen = null | mingwen. equals ("") {} else {BASE64Encoder encoder = new BASE64Encoder (); try {code = encoder. encode (mingwen. getBytes ();} catch (Exception e) {e. printStackTrace ();} // System. out. println ("encrypted [" + code + "]");} return code;} public static String decodeBase64 (String mi) {String mingwen = ""; if (mi = null | mi. equals ("") {} else {BASE64Decoder decoder = new BASE64Decoder (); try {byte [] by = decoder. decodeBuffer (mi); mingwen = new String (by);} catch (Exception e) {e. printStackTrace ();} // System. out. println ("decrypted [" + mingwen + "]");} return mingwen ;}/ * print: test plaintext [suolong2014version] [encrypted] [encrypted] [suolong2014version] After decryption N times encryption test -------- after encryption 2 times [encrypted] After decryption 2 times [suolong2014version] After encryption 5 times [encrypted]] [suolong2014version] */
From the results, jquery. base64.js encryption and decryption are the same as java's base64 encryption and decryption.
PS: here we recommend several online encryption and decryption tools for your reference:
Line encoding conversion tool (UTF-8/utf-32/Punycode/Base64 ):
Http://tools.jb51.net/transcoding/decode_encode_tool
BASE64Encoding and decoding tools:
Http://tools.jb51.net/transcoding/base64
Online tools for converting images to Base64 encoding:
Http://tools.jb51.net/transcoding/img2base64
Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tools:
Http://tools.jb51.net/password/hash_md5_sha