help icon indicating copy to clipboard operation
help copied to clipboard

digital envelope routines::unsupported with .mjs

Open ape-byte opened this issue 1 year ago • 0 comments

Details

The first time I used the node .mjs script, I encountered this problem.

(See Example code)

This is just a simple single Demo script. Its file suffix is'. mjs'

On this issue, I refer to stackoverflow,And tried to input set NODE_OPTIONS=--openssl-legacy-provider at the vscode terminal. But it didn't work

I don't want to reduce the version of nodejs, and I don't want to attach other files. Who can tell me how to solve this problem gracefully? 😣

Node.js version

v20.11.1

Example code

import crypto from 'node:crypto';

var obj = {
    code: "GM10001",
    stamp: (new Date()).getTime()
}
var json = JSON.stringify(obj);

var key = Buffer.from("pmQG0EzAXjV1UBCBw4hdDRRKgYnZErCb", "utf8");
var iv = Buffer.from("L434o3PH", "utf8");

//nodejs crypto
var cipher = crypto.createCipheriv('des-cbc', key, iv);   //throw error  0308010C:digital envelope routines::unsupported
var crypted = cipher.update(json, 'utf8', 'hex');
crypted += cipher.final('hex');

console.log(crypted);

Operating system

windows 11
Code edit in vscode

Scope

None

Module and version

Not applicable.

ape-byte avatar Mar 25 '24 14:03 ape-byte