


About jQuery implementing base64 front-end encryption and decryption function
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:
<title></title> <meta> <script></script> <script></script> <input> <input> <br> <input> <br> 加密后:<input> <br> <input> <br> <br> <hr> <input> <br> 加密后:<input> <br> <input> <br> <br> <input> <br> <textarea></textarea> <script> var path=document.getElementById("path").value; function app(info){ $("#txt").val($("#txt").val()+'\n'+info); } function subfunc(){ var put1=$.trim($("#putcardno01").val()); // var estxt=$.base64.encode(put1); //var estxt=$.base64.btoa(put1); var estxt=encodeBase64(put1); $("#putcardno02").val(estxt); app("加密后["+estxt+"]"); } function subfunc02(){ var put1=$.trim($("#putcardno02").val()); //var estxt=$.base64.decode(put1); //var estxt=$.base64.atob(put1); var estxt=decodeBase64(put1); app("解密后["+estxt+"]"); } ////////////////////////////////////////// var numTimes=5; function subfunc03(){ var put1=$.trim($("#putcardno01").val()); // var estxt=$.base64.encode(put1); //var estxt=$.base64.btoa(put1); //estxt=$.base64.btoa(estxt); estxt=encodeBase64(put1,numTimes); $("#putcardno03").val(estxt); app(numTimes+"次加密后["+estxt+"]"); } function subfunc04(){ var put1=$.trim($("#putcardno03").val()); //var estxt=$.base64.decode(put1); //var estxt=$.base64.atob(put1); //estxt=$.base64.atob(estxt); estxt=decodeBase64(put1,numTimes); app(numTimes+"次解密后["+estxt+"]"); } function clearrr(){ $("#putcardno02").val(""); $("#putcardno03").val(""); $("#putcardno04").val(""); $("#txt").val(""); } //加密方法。没有过滤首尾空格,即没有trim. //加密可以加密N次,对应解密N次就可以获取明文 function encodeBase64(mingwen,times){ var code=""; var num=1; if(typeof times=='undefined'||times==null||times==""){ num=1; }else{ var vt=times+""; num=parseInt(vt); } if(typeof mingwen=='undefined'||mingwen==null||mingwen==""){ }else{ $.base64.utf8encode = true; code=mingwen; for(var i=0;i<num;i++){ code=$.base64.btoa(code); } } return code; } //解密方法。没有过滤首尾空格,即没有trim //加密可以加密N次,对应解密N次就可以获取明文 function decodeBase64(mi,times){ var mingwen=""; var num=1; if(typeof times=='undefined'||times==null||times==""){ num=1; }else{ var vt=times+""; num=parseInt(vt); } if(typeof mi=='undefined'||mi==null||mi==""){ }else{ $.base64.utf8encode = true; mingwen=mi; for(var i=0;i<num;i++){ mingwen=$.base64.atob(mingwen); } } return mingwen; } /* 测试 输入 suolong2014version 加密后[c3VvbG9uZzIwMTR2ZXJzaW9u] 解密后[suolong2014version] 5次加密后[VjFod1QxWXlVblJUYTJoUVYwWmFhRnBYZEhOTk1WSlhWV3hPVG1KSVFscFZNalYzWVVaYU5tSkVSVDA9] 5次解密后[suolong2014version] */ </script>
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<p>From the results, jquery.base64.js encryption and decryption are the same as java’s base64 encryption and decryption. </p><p>Related recommendations: <br></p><p><a href="http://www.php.cn/php-weizijiaocheng-382355.html" target="_self">How does PHP use a custom key to encrypt and decrypt data?</a></p><p><a href="http://www.php.cn/java-article-382140.html" target="_self">Java encryption and decryption and Digital signature complete code example</a></p><p><a href="http://www.php.cn/toutiao-380825.html" target="_self">php data encryption related introduction</a></p>
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!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools