codesandbox.ioにSign up
dashboard>Create>Quick start>Node.js
index.jsに以下を貼り付け、CTRL+Sで保存すると、実行結果が表示される
const crypto = require("crypto");
const algorithm = "des-ecb";
const key = Buffer.from("mykeystr", "utf-8"); // 8バイト
const cipher = crypto.createCipheriv(algorithm, key, null);
const encrypted =
cipher.update("暗号化対象文字列", "utf8", "hex") + cipher.final("hex");
console.log(encrypted);
const decipher = crypto.createDecipheriv(algorithm, key, null);
console.log(decipher.update(encrypted, "hex", "utf8") + decipher.final("utf8"));