js中的加密问题
crypt problrm in js
我有从文件 info.txt 解密密码的草图,当我转到 http://localhost:8080:
时给我发邮件
var crypto = require('crypto'); // encryption/decryption tool
var fs = require('fs'); // filesystem manager
var express = require('express'); // web server
var nodemailer = require('nodemailer'); // email
var key = process.argv[3];
var fileName = __dirname + "/info.txt";
var decipher = crypto.createDecipher('aes-256-cbc', key);
var server = express();
server.use('/',express.static('public'));
var account = {
host: 'smtp.gmail.com', // mail server
port: 465, // SSL mail port
secure: true, // using secure sockets for mail
auth: {
user: process.argv[2], // username from the commnand line
pass: '' // password will come from decryption later
}
};
var message = {
from: account.auth.user,
to: 'z.zitsw@gmail.com', //''cat.owner@example.com',
subject: 'Hello from the cat',
text: 'The cat is sitting on his mat! http://www.example.com/catcam.html'
};
function sendMail(request, response) {
// callback function to confirm mail was sent and inform web client
var mailClient = nodemailer.createTransport(account);
var responseString = mailClient.sendMail(message, confirmMail);
}
function decryptFile(error, data) {
// if there's valid data from the file, decrypt it:
if (data){
var content = data.toString();
var decryptedPassword = decipher.update(content, 'hex', 'utf8');
decryptedPassword += decipher.final('utf8');
account.auth.pass = decryptedPassword;
// if the file produces an error, report it:
} else if (error) {
console.log(error);
}
}
// read from the password file:
fs.readFile(fileName, decryptFile);
console.log("credentials for " + account.auth.user + " obtained.");
// start the server:
server.listen(8080);
server.get('/mail', sendMail); // send a mail
console.log("waiting for web clients now.");
但是当我在终端中 运行 应用程序(节点 server.js my_mail 键)时,我收到此错误:
(节点:7392)[DEP0106]弃用警告:crypto.createDecipher 已弃用。
(使用 node --trace-deprecation ...
显示创建警告的位置)
internal/validators.js:198
抛出新的 ERR_INVALID_ARG_VALUE('encoding', 编码
请帮帮我
所以对我来说,这意味着函数 createDecipher 不再受支持?也许如果您查看 crypto 包的文档,可能会有解释或替代方法来解决这个问题。
我有从文件 info.txt 解密密码的草图,当我转到 http://localhost:8080:
时给我发邮件var crypto = require('crypto'); // encryption/decryption tool
var fs = require('fs'); // filesystem manager
var express = require('express'); // web server
var nodemailer = require('nodemailer'); // email
var key = process.argv[3];
var fileName = __dirname + "/info.txt";
var decipher = crypto.createDecipher('aes-256-cbc', key);
var server = express();
server.use('/',express.static('public'));
var account = {
host: 'smtp.gmail.com', // mail server
port: 465, // SSL mail port
secure: true, // using secure sockets for mail
auth: {
user: process.argv[2], // username from the commnand line
pass: '' // password will come from decryption later
}
};
var message = {
from: account.auth.user,
to: 'z.zitsw@gmail.com', //''cat.owner@example.com',
subject: 'Hello from the cat',
text: 'The cat is sitting on his mat! http://www.example.com/catcam.html'
};
function sendMail(request, response) {
// callback function to confirm mail was sent and inform web client
var mailClient = nodemailer.createTransport(account);
var responseString = mailClient.sendMail(message, confirmMail);
}
function decryptFile(error, data) {
// if there's valid data from the file, decrypt it:
if (data){
var content = data.toString();
var decryptedPassword = decipher.update(content, 'hex', 'utf8');
decryptedPassword += decipher.final('utf8');
account.auth.pass = decryptedPassword;
// if the file produces an error, report it:
} else if (error) {
console.log(error);
}
}
// read from the password file:
fs.readFile(fileName, decryptFile);
console.log("credentials for " + account.auth.user + " obtained.");
// start the server:
server.listen(8080);
server.get('/mail', sendMail); // send a mail
console.log("waiting for web clients now.");
但是当我在终端中 运行 应用程序(节点 server.js my_mail 键)时,我收到此错误:
(节点:7392)[DEP0106]弃用警告:crypto.createDecipher 已弃用。
(使用 node --trace-deprecation ...
显示创建警告的位置)
internal/validators.js:198
抛出新的 ERR_INVALID_ARG_VALUE('encoding', 编码
请帮帮我
所以对我来说,这意味着函数 createDecipher 不再受支持?也许如果您查看 crypto 包的文档,可能会有解释或替代方法来解决这个问题。