Node. js Data Encryption Transmission Analysis, node. js Data Encryption

Source: Internet
Author: User
Tags pfx file

Node. js Data Encryption Transmission Analysis, node. js Data Encryption

Preface

For encrypted data transmission, there are several methods that people often use. One is ciphertext transmission, and the other is ciphertext transmission. The other is to encrypt data using keys and decrypt data using public keys, the transmission channel can be https or http. The premise of plaintext transmission is to establish a secure transmission channel. Here, the certificate is used to protect the security of the channel, and then the data is transmitted in plaintext.

If you are a professional user, you can share it later. But here I will introduce the plaintext transmission. If you use nodejs to establish a secure channel

Use two libraries: urllib and request. Here the certificate only describes how to use the pfx File

Urllib library Method

const urllibRequest = (url, method, data, pfx, pass) => { return new Promise(function(resolve, reject) {  let options = {   data: data,   method: method,   pfx: pfx,   passphrase: pass,   rejectUnauthorized: false  }  urllib.request(url, options, function(err, data, res) {   if (err) {    return reject(err);   }   return resolve(data.toString());  }); });}

Request library Method

const httpRequest = (url, method, data, pfx, pass) => { return new Promise((resolve, reject) => {  let options = {   url: url,   method: method,   form: data,   headers: {    'Content-type': 'application/x-www-form-urlencoded'   },   agentOptions: {    pfx: pfx,    passphrase: pass,    rejectUnauthorized: false   }  };  request(options, function(err, httpResponse, data) {   if (err) {    return reject(err);   }   return resolve(data);  }) });}

Summary

The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

Related Article

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.