This article mainly introduces jQuery's implementation of base64 front-end encryption and decryption functions. It analyzes the implementation method of jquery.base64.js to implement front-end base64 encryption and decryption functions in the form of examples, and gives a comparison of operation examples of java's implementation of back-end base64 encryption and decryption. To verify the encryption effect, friends who need it can refer to it. I hope it can help everyone.
Regarding 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's DES, jQuery on the Internet has jquery.base64.js.
(For md5 encryption of js, you can use jquery.md5.js. If you are interested, you can find it and test it).
The following is the test:
Is the encryption and decryption in the background the same as in the front desk?
Let’s test it:
package com.code; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; /** * * Base64加密--解密 * * @author lushuaiyin * */ public class Base64Util { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String str="suolong2014version"; System.out.println("测试明文["+str+"]"); String basecode =Base64Util.encodeBase64(str); System.out.println("加密后["+basecode+"]"); if(basecode!=null){ String res =Base64Util.decodeBase64(basecode); System.out.println("解密后["+res+"]"); } ///////////////////////////////////////// System.out.println(""); System.out.println("N次加密测试--------"); String basecodeN=Base64Util.encodeBase64(str, 2); String resN=Base64Util.decodeBase64(basecodeN, 2); String basecodeN3=Base64Util.encodeBase64(str, 5); String resN3=Base64Util.decodeBase64(basecodeN3, 5); } //提供加密N次 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 Copy after login
From the results, jquery.base64.js encryption and decryption are the same as java’s base64 encryption and decryption.
Related recommendations:
How does PHP use a custom key to encrypt and decrypt data?
Java encryption and decryption and Digital signature complete code example
php data encryption related introduction
The above is the detailed content of About jQuery implementing base64 front-end encryption and decryption function. For more information, please follow other related articles on the PHP Chinese website!