NodeJS Crypto Encryption Production TOKEN’s implementation code

Node.js built-in Crypto library, which provides a variety of encryption algorithms that can easily let us use cryptographic technology to solve problems in application development. Mainly supports Hash (Hash), HMAC (Key Hobs), Cipher, Decipher (Decoding), Sign (Signature), and Verify. Crypto English is the meaning of secret members.

The usage method is approximately as follows:

Crypto.createhash (Algorithm) Specifies the encryption method


 VAR CRYPTO = Require ("CRYPTO"); // Encryption Crypto.getHashes ()   Displays the internal supported encryption method. 
Hash.Update (data) Specifies the content (DATA)

Hash.Digest (“HEX”) to be encrypted, which can be HEX Binary or Base64.

  • VAR CRYPTO = Require (“Crypto”); // Encrypted VAR A = Crypto.createhash (“MD5 “) .Update (” 12 “). DiGest (‘base64’); console.log (a)
encrypted result is the same as C20AD4D76FE97759AA27A0C99BFF6710 comparison using MD5 encryption tool encryption

Second, the production token
   
// Login App.Post (“/ login”, (Req, Res) => {// Handling POST request var form = new formidable.incomingform (); form.parse (REQ, FUNCTION (ERR, Fields, files) {// Decide whether to log in correctly User.Find ({“Username”: Fields.userName, “Password”: Fields.password}). EXEC ((Err, DOCS) => {if (DOCS.LENGTH) {// Login success Req.session.login = true; req.session.usename = fields.username; var token = crypto.createhash (“SHA256”). Update (Fields.userName + Fields.userName) .digest (‘HEX ‘); Res. Json ({“:”: token});} else {res. json ({“{“: -1});}});});};

The above is all the content of this article, I hope that everyone’s learning is helpful, and I hope you will support Tumi Clouds. NodeJs crypto加密制作token的实现代码

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment