Я пытаюсь зашифровать и расшифровать строку в cookieStorage, но когда я выполняю свой код, у меня появляется сообщение, что этот метод устарел и не работает
Мой код:
const crypto = requite('crypto');
app.get("/crypto", (req, res) => {
var word = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlMzBiZjE0YmQ4OTNmMmE5Y2Q1Y2I5MSIsInJvbGVzIjoiVVNFUl9ST0xFIiwiZW1haWwiOiJjYW1lcmF0ZXN0ODExQGdtYWlsLmNvbSIsImlhdCI6MTU4MDMzNjc1MCwiZXhwIjoxNTgwMzk2NzUwfQ.2bbqkoX7qhyX7lyLjBtlGPe08-oHGjO83nNIPxAzHv8";
var algorithm = "aes-256-ct";
var password = "3zTvzr3p67VC61jmV54rIYu1545x4TlY";
var hw = encrypt(word, algorithm, password);
console.log("encrypt: ", hw);
console.log("decrypt: ", decrypt(hw, algorithm, password));
});
function encrypt(text, algorithm, password) {
var cipher = crypto.createCipher(algorithm, password);
var crypted = cipher.update(text, "utf8", "hex");
crypted += cipher.final("hex");
return crypted;
}
function decrypt(text, algorithm, password) {
var decipher = crypto.createDecipher(algorithm, password);
var dec = decipher.update(text, "hex", "utf8");
dec += decipher.final("utf8");
return dec;
}