Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digital envelope routines::unsupported with .mjs #4365

Open
HaoDong108 opened this issue Mar 25, 2024 · 4 comments
Open

digital envelope routines::unsupported with .mjs #4365

HaoDong108 opened this issue Mar 25, 2024 · 4 comments

Comments

@HaoDong108
Copy link

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.

@Trott
Copy link
Member

Trott commented Apr 5, 2024

@nodejs/crypto

@tniessen
Copy link
Member

tniessen commented Apr 6, 2024

@HaoDong108 Why are you using des-cbc?

@HaoDong108
Copy link
Author

@HaoDong108 Why are you using ?des-cbc
I want to use it to make a signed Demo, which is used to give the counterpart a demonstration example that can be run directly.
But I don't think it has anything to do with what encryption algorithm I use. The question is, it is wrong and strange, or am I using it incorrectly?

@HaoDong108
Copy link
Author

I can't understand why a code that only needs to be implemented purely by algorithm would encounter errors that seem completely unrelated to the calculation process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants