The use of crypto in the Web

Source: Internet
Author: User
Tags base64 hmac sha1

Objective

Crypto is a core module in Nodejs, although there is now a Crypto global object () in the Advanced browser, and its use in Nodejs is different from the web side.

Web-side Use Cryptojs
    1. Foreign download slower, recommended domestic mirror
      Link: Https://pan.baidu.com/s/1jKgTAZW Password: 0HPI
    2. How to use:
    • Using encryption methods in Nodejs
      javascript var crypto = require(‘crypto‘); var PRIVATE_KEY = ‘123‘; var hmac = crypto.createHmac(‘sha1‘, private_key); hmac.write(url); hmac.end(); var key = hmac.read().toString(‘base64‘); key = encodeURIComponent(key);
    • Switch to web-side use

html <!-- html中代码 --> <!-- 根据上面代码使用引入相应的js --> <script src="cryptojs/rollups/hmac-sha1.js"></script> <script src="cryptojs/components/enc-base64-min.js"></script>

javascript // js中代码 var PRIVATE_KEY = ‘123‘; var hash = CryptoJS.HmacSHA1(url, private_key); var base64 = hash.toString(CryptoJS.enc.Base64); var key = encodeURIComponent(base64);

    1. Let's try it yourself!

The use of crypto in the Web

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.