WeChat applet development function introduction: encryption and decryption NODE-UUID

Source: Internet
Author: User
Tags hmac
Small program development function introduction: encryption and decryption NODE-UUID,

Node-uuid can quickly generate UUID that complies with RFC4122 Specification version 1 or version 4. The js-base64 can realize Base64 encoding and decoding, and supports UTF-8 encoding. Crypto-js can be very convenient in JavaScript MD5, SHA1, SHA2, SHA3, RIPEMD-160 hash, AES, DES, Rabbit, RC4, Triple DES encryption and decryption. SJCL is a project created by the computer security lab of Stanford University. it aims to create a secure, fast, short, easy-to-use, cross-browser JavaScript encryption library.


Node-uuid

Node-uuid can quickly generate UUID (Universally Unique IDentifier) that complies with RFC4122 Specification version 1 or version 4 ).

The emergence of UUID is to uniquely identify each information entity in a complex system without a centralized id management. That is to say, a rule is used to assign a unique id to an information entity, 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 ensures the uniqueness of the generated ID through MAC address, timestamp, namespace, random number, and pseudo-random number. Version 1 is time-based, and version 1 is random (

Version1:


[AppleScript]

Var uuidv1 = require ('../lib/uuid/we-uuidv1'); console. log (uuidv1 (); // output: 70d47fd0-d250-11e6-9816-45a4888ae4f

Version4:

[AppleScript]

Var uuidv4 = require ('../lib/uuid/we-uuidv4'); console. log (uuidv4 (); // output: d839476c-ce27-4d24-a431-e96123c1916b

Generate parameters can be set

[AppleScript]

Var v1 = uuidv1 ({node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], clockseq: 0x1234, msecs: new Date (). getTime (), nsecs: 5678}); console. log (v1); // output: 908e3a9e-d250-11e6-9234-0123456789ab

The js-base64 can realize Base64 encoding and decoding, and supports UTF-8 encoding.

Base64 is a representation of binary data based on 64 printable characters. Because the power of 6 in 2 is equal to 64, every 6 bits are a unit and correspond to a printable character. The three bytes have 24 bits, which correspond to four Base64 units. that is, the three bytes are represented by four printable characters. It can be used as the transmission code of the email. The printable characters in Base64 include letters A-Z, a-z, and numbers 0-9, which have A total of 62 characters. the Two printable characters are different in different systems.

Base64 is actually a simple replacement encryption method, but BASE64 is often not used to prevent information leakage, and to facilitate transmission, after BASE64 encoding, the information will be longer than the original information, about 4/3 times.

Encoding:

Console. log (Base64.encode ('WeChat '));// Output: v2vjaf0Console. log (Base64.encode (''));// Output: 5b6u5L + h

Decoding:

Console. log (Base64.decode ('v2vjarf0 '));// Output: WechatConsole. log (Base64.decode ('5b6u5l + h '));// Output:Crypto-js

Crypto-js can be very convenient in JavaScript MD5, SHA1, SHA2, SHA3, RIPEMD-160 hash, AES, DES, Rabbit, RC4, Triple DES encryption and decryption.

CryptoJS (crypto. js) provides various encryption algorithms for JavaScript. Currently, the 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: 42989457d716a8b89f99c687a10979d4242b5491

SHA256:

Console. log (CryptoJS. SHA256 ('WeChat'). toString ());// Output: SuccessSJCL

SJCL is a project created by the computer security laboratory of Stanford University, it is designed to create a secure, fast, short, easy-to-use, cross-browser JavaScript encryption library.

SJCL uses the industry standard AES 128,192,256-bit encryption; SHA256 hash function; HMAC verification code; PBKDF2 cryptographic enhancement; CCM and OCB authentication encryption mode.

Encryption:

VarEnStr = sjcl. encrypt ("password", "Wechat"); console. log (enStr );

Decryption:

VarDeStr = sjcl. decrypt ("password", enStr); console. log (deStr );References
  • Node-uuid @ github

  • Js-base64 @ github

  • Crypto-js @ github

  • SJCL

  • SJCL @ github

  • JavaScript Crypto-JS User Manual

  • SJCL: Stanford University JS Keystore

Others
  • Full: https://github.com/guyoung/GyWxappCases/tree/master/Enhance

  • Applet Canvas enhancement component WeZRender: https://github.com/guyoung/WeZRender

The above is the introduction of small program development function: detailed content of encryption and decryption NODE-UUID, more please pay attention to the first PHP community other related articles!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.