我在NodeJS v8.11.0中使用以下代码生成了base64编码的密钥:
const secret = 'shezhuansauce';
const key = crypto.createHash('sha256').update(String(secret)).digest('base64');
//output is REtgV24bDB7xQYoMuypiBASMEaJbc59nJWChoXbbmsA=
Run Code Online (Sandbox Code Playgroud)
使用密钥,我尝试加密一个字符串:
var tobeEncrypted = 'some secret string';
const iv = crypto.randomBytes(16).toString('hex').slice(0, 16);
const cipher = crypto.createCipheriv('aes-256-ctr', key, iv);
const encrypted = cipher.update(String(tobeEncrypted), 'utf8', 'hex') + cipher.final('hex');
console.log(encrypted);
Run Code Online (Sandbox Code Playgroud)
但是,我收到一个错误:
crypto.js:219
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
^
Error: Invalid key length
Run Code Online (Sandbox Code Playgroud)
密钥必须是base64字符串,因为我会将其存储在Cloud服务中,并且它仅接收base64字符串。
任何帮助表示赞赏。
我目前正在编写一个简单的批处理脚本来自动设置LAN连接的DNS.这是脚本:
REM Set DNS
netsh interface ip set dns name="Local Area Connection" static X.X.X.X
netsh interface ip add dns name="Local Area Connection" Y.Y.Y.Y index=2
netsh interface ip add dns name="Local Area Connection" Z.Z.Z.Z index=3
Run Code Online (Sandbox Code Playgroud)
但问题是,如果局域网名称不是默认值(即本地连接),则脚本将无法运行.
有没有什么办法可以检测所有的本地连接名称,并使用批处理文件设置所有这些LAN连接的DNS?
任何帮助将不胜感激 :)