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

Minified forge does not require node crypto #783

Open
mattnotmitt opened this issue May 27, 2020 · 3 comments
Open

Minified forge does not require node crypto #783

mattnotmitt opened this issue May 27, 2020 · 3 comments

Comments

@mattnotmitt
Copy link

I'm not sure what the issue is but from inspecting the minified JS for forge, it does not run the require('crypto') even if forge determines the environment is Node.

@mattnotmitt mattnotmitt changed the title Minimized forge does not require node crypto Minified forge does not require node crypto May 27, 2020
@davidlehn
Copy link
Member

The minified code is meant to be used in a browser. When using Node.js you should use require('node-forge') and it should do the right thing. Why were you using the minified code in Node.js?

The node/browser switching code is rather ancient. It predates all modern tools. When the code gets a major refactor it's likely newer constructs will be used. It's a bit tricky in the case of crypto and this library as this is a crypto library. In theory pieces of crypto could be written with forge and vice versa. Same with WebCrypto in the browser. I'm not sure what the latest webpack conversion did to the node/browser switch paths, but it may have partly optimized out something expecting the browser path?

@mattnotmitt
Copy link
Author

We use minified forge for crypto in https://github.com/gchq/CyberChef which is a webapp but for unit testing we use a node environment so tests for individual operations which rely on minified forge don't work.

@oxygen
Copy link

oxygen commented Dec 8, 2020

There are legitimate use cases where code is at least bundled as a single file (usually using webpack and maybe even babel) in nodejs, such as more easily distributing code - many times by including a single output js file in a nexe build.

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