Home >WeChat Applet >Mini Program Development >Introduction to WeChat Mini Program Development Functions: Introduction to Encryption and Decryption NODE-UUID
node-uuid can quickly generate UUIDs that comply with RFC4122 specification version 1 or version 4. js-base64 can implement Base64 encoding and decoding, and supports UTF-8 encoding. crypto-js can easily perform MD5, SHA1, SHA2, SHA3, RIPEMD-160 hashing, and AES, DES, Rabbit, RC4, Triple DES encryption and decryption in JavaScript. SJCL is a project created by the Stanford University Computer Security Laboratory, aiming to create a secure, fast, short and concise, easy-to-use, cross-browser JavaScript encryption library. node-uuid can quickly generate RFC4122 specifies the UUID (Universally Unique IDentifier, identifier) of version 1 or version 4. The emergence of UUID is to uniquely identify each information entity in a complex system without the need for a centralized ID management. That is to say, an information entity is assigned a unique ID according to certain rules, and an ID manager is not required to ensure the uniqueness of this ID. UUID is a 128-bit globally unique identifier, usually represented by a 32-byte string. It uses MAC address, timestamp, namespace, random number, and pseudo-random number to ensure the uniqueness of the generated ID. version 1 is generated based on timestamp (time-based); version 1 is generated randomly (random( Version1:var uuidv1 = require('../../lib/uuid/we-uuidv1'); console.log(uuidv1()); // 输出:70d47fd0-d250-11e6-9816-45a4888ae4f Version4: var uuidv4 = require('../../lib/uuid/we-uuidv4'); console.log(uuidv4()); // 输出:d839476c-ce27-4d24-a431-e96123c1916b You can set the generation parameters var v1 = uuidv1({ node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], clockseq: 0x1234, msecs: new Date().getTime(), nsecs: 5678 }); console.log(v1); // 输出:908e3a9e-d250-11e6-9234-0123456789ab js-base64 can implement Base64 encoding and decoding, and supports UTF-8 encoding. Base64 is a representation method of binary data based on 64 printable characters. Since 2 to the 6th power is equal to 64, every 6 bits are a unit, corresponding to a certain printable character. There are 24 bits, corresponding to 4 Base64 units, that is, 3 bytes need to be represented by 4 printable characters. It can be used as the transmission encoding of email. The printable characters in Base64 include the letters A-Z, a-z, Numbers 0-9, so there are 62 characters in total. The other two printable symbols are different in different systems. Base64 is actually a simple substitution encryption method, but BASE64 The purpose is often not to prevent information leakage, but to facilitate transmission, the BASE64-encoded information will be longer than the original information, about 4/3 times longer. Encoding: console.log(Base64.encode('Wechat')); // Output: V2VjaGF0 console.log(Base64.encode('WeChat')); // Output: 5b6u5L+hDecoding: console.log(Base64.decode('V2VjaGF0')); // Output: Wechat console.log(Base64.decode('5b6u5L+h')); // Output: WeChatcrypto-jscrypto-js can easily perform MD5, SHA1, SHA2, SHA3, RIPEMD-160 hashing, and AES, DES, Rabbit, RC4, Triple DES encryption and decryption in JavaScript #CryptoJS (crypto.js) provides a variety of encryption algorithms for JavaScript. Currently supported algorithms include:
MD5:console.log(CryptoJS.MD5('Wechat').toString()); // Output: 98ffdc1f1a326c9f73bbe0b78e1d180e SHA1: console.log(CryptoJS.SHA1('Wechat').toString()); // Output :42989457d716a8b89f99c687a41779d4102b5491SHA256: console.log(CryptoJS.SHA256('Wechat').toString() ; A project founded by the team's office, it aims to create a secure, fast, short and concise, easy-to-use, cross-browser JavaScript encryption library. SJCL uses industry-standard AES 128, 192, 256-bit encryption; SHA256 hash function; HMAC verification code; PBKDF2 password strengthener; CCM and OCB authentication encryption modes.Encryption: var enStr = sjcl.encrypt("password" ,"Wechat"); console .log(enStr);Decryption: var deStr = sjcl.decrypt("password" , enStr);console.log(deStr);Reference materials node-uuid@githubjs-base64@github
|
The above is the detailed content of Introduction to WeChat Mini Program Development Functions: Introduction to Encryption and Decryption NODE-UUID. For more information, please follow other related articles on the PHP Chinese website!