Home > Article > WeChat Applet > Introduction to WeChat applet development functions: 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:[AppleScript] var uuidv4 = require('../../lib/uuid/we-uuidv4'); console.log(uuidv4()); // 输出:d839476c-ce27-4d24-a431-e96123c1916b You can set the generation parameters [AppleScript]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 based on 64 printable characters. Representation method of binary data. Since 2 raised to the 6th power is equal to 64, each 6 bits is a unit, corresponding to 24 bits of a certain printable character, 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 letters A-Z, a-z, numbers 0-9, so there are 62 characters in total, and the other two. Printable symbols vary in different systemsBase64 is actually a simple substitution encryption method, but the use of BASE64 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 ##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 be very Conveniently 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
MD5: console.log(CryptoJS.MD5('Wechat').toString()); // Output: 98ffdc1f1a326c9f73bbe0b78e1d180eSHA1: console.log(CryptoJS.SHA1('Wechat ').toString()); // Output: 42989457d716a8b89f99c687a41779d4102b5491SHA256: console. log(CryptoJS.SHA256('Wechat').toString()); // Output: 885e2deda21a6c752f05e9c3ac95c90de31bce4b25ce38c330feee389906c83fSJCLSJCL (Stanford University Javascript Encryption Library) is a project founded by the Stanford University Computer Security Laboratory, aiming to create a safe, 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
|
The above is the detailed content of Introduction to WeChat applet development functions: encryption and decryption NODE-UUID. For more information, please follow other related articles on the PHP Chinese website!