With regard to encryption, many people think of encodeURI and escape. This is useful for encrypting URLs, especially URLs with Chinese parameters.
If you just want to do encryption and decryption, similar to Java des, online jquery has a jquery.base64.js.
(about JS MD5 encryption can be used jquery.md5.js, interested can be found to test it).
Here is the test:
Encryption and decryption in the background is not the same as the foreground.
Let's Test it:
Package Com.code;
Import Sun.misc.BASE64Decoder;
Import Sun.misc.BASE64Encoder; /** * * BASE64 Encryption--Decrypt * * @author lushuaiyin * * */public class Base64util {/** * @param args */public stat
IC 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 ("After encryption [" +basecode+ "]");
if (basecode!=null) {String res =base64util.decodebase64 (Basecode);
System.out.println ("After decryption [" +res+ "]");
}/////////////////////////////////////////System.out.println ("");
System.out.println ("N-Times Encryption Test--------");
String basecoden=base64util.encodebase64 (str, 2);
String resn=base64util.decodebase64 (Basecoden, 2);
String basecoden3=base64util.encodebase64 (str, 5);
String resn3=base64util.decodebase64 (basecodeN3, 5); }//provides encryption n times public static string EncodeBase64 (String mingwen,int times) {int num=<=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 ("Encrypt" +num+ "Times [" +code+ "]");
} return code;
}//corresponds to provide decrypt n times 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 ("Decrypt" +num+ "Times [" +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 ("After encryption [" +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 ("After decryption [" +mingwen+ "]");
} return Mingwen; }/* Print: After testing plaintext [suolong2014version] after [c3vvbg9uzziwmtr2zxjzaw9u] decryption [suolong2014version] n Encryption test--------encrypted 2 times [YZNWD MJHOXVAEKL3TVRSMLPYSNPHVZL1] After decryption 2 times [suolong2014version] encrypted 5 times after [ Vjfod1qxwxlvbljuytjouvywwmfhrnbyzehotk1wslhwv3hpvg1ksvfscfznalyzwvvayu5tskvs VDA9] Decryption 5 times [suolong2014version] */
From the results, jquery.base64.js encryption and decryption are the same as Java's Base64 encryption and decryption.