Introduction to WeChat applet development functions: encryption and decryption NODE-UUID

巴扎黑
Release: 2017-04-01 15:32:25
Original
2478 people have browsed it

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

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:


[AppleScript]

 var uuidv1 = require('../../lib/uuid/we-uuidv1');    console.log(uuidv1()); // 输出:70d47fd0-d250-11e6-9816-45a4888ae4f
Copy after login


Version4:

[AppleScript]

var uuidv4 = require('../../lib/uuid/we-uuidv4');    console.log(uuidv4()); // 输出:d839476c-ce27-4d24-a431-e96123c1916b
Copy after login

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
Copy after login


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 systems

Base64 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
  • SHA-1
  • SHA-256
  • AES
  • Rabbit
  • ##MARC4

  • HMAC


  • HMAC-MD5
    • HMAC-SHA1

    • HMAC-SHA256


    • PBKDF2

MD5:

console.log(CryptoJS.MD5('Wechat').toString()); // Output: 98ffdc1f1a326c9f73bbe0b78e1d180e

SHA1:

console.log(CryptoJS.SHA1('Wechat ').toString()); // Output: 42989457d716a8b89f99c687a41779d4102b5491

SHA256:

console. log(CryptoJS.SHA256('Wechat').toString()); // Output: 885e2deda21a6c752f05e9c3ac95c90de31bce4b25ce38c330feee389906c83fSJCL

SJCL (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
  • node-uuid@github

  • js-base64@github

  • crypto-js@github

  • ##SJCL

  • SJCL@github

  • JavaScript Crypto-JS User Manual

  • SJCL: Stanford University JS Crypto Library


Others
  • Full code:

    https://github.com/guyoung/GyWxappCases/tree/master/Enhance

  • WeChat applet Canvas enhanced component WeZRender:

    https://github.com/guyoung/WeZRender

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!