Analysis of Node.js Data encryption transmission _node.js

Source: Internet
Author: User
Tags pfx file

Objective

Data encryption transmission, we often contact a number of ways one is ciphertext transmission, a clear text transmission ciphertext transmission, that is, the data encryption with the key, using the public key to decrypt the data, the transmission channel can be HTTPS or HTTP. PlainText transmission, provided that a secure transmission channel is established, where a certificate is used to protect the security of the channel, then the data is transmitted and the plaintext is used.

More professional can be later to share, but here I will introduce the clear text transmission, if it is to use Nodejs to establish a secure channel

Use two libraries, respectively Urllib and request, where the certificate only describes the use of a PFX file

Ways to Urllib libraries

Const Urllibrequest = (URL, method, data, PFX, pass) => {return to
 new Promise (function (resolve, reject) {Let
  op tions = {
   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 ());});}

The method of the request library

Const HttpRequest = (URL, method, data, PFX, pass) => {return to
 new Promise (Resolve, reject) => {let
  option s = {
   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);})
 }

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.