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.