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

Platform Detection Error on Node #1741

Open
bootexe opened this issue Sep 22, 2024 · 0 comments
Open

Platform Detection Error on Node #1741

bootexe opened this issue Sep 22, 2024 · 0 comments

Comments

@bootexe
Copy link

bootexe commented Sep 22, 2024

Hello first I want to thank you for this amazing work you've done unifying both webcrypto and node crypto API
I just encountered an error when I was trying to execute aes encrpytion with js-crpyto-aes on my ExpressJs server
i was getting an error saying that my iv was not an instance of Buffer or ArrayBuffer even when it is a Buffer Instance and then I saw in my StackTrace that the error comes from a webapi.js file
so I investigate some file in node_modules and i found this js-crypto-env library which seem to detect incorrectly the platform iam running
btw iam running on node 22.3.0 npm 10.8.1
so i force the use of require('crypto') in the index.js fil of js-crypto-env and now everything seems to work for me

this is the new function I replaced

var getCrypto = function () {
    var webCrypto = getWebCrypto();
    var nodeCrypto = getNodeCrypto();
    nodeCrypto = require('crypto'); // I added this line
    console.log(nodeCrypto)
    if (typeof nodeCrypto !== 'undefined'){
        console.error('Crypto NODE')//this was to be sure what I was modifying 
        return { name: 'nodeCrypto', crypto: nodeCrypto };
    }
        
    else if (typeof webCrypto !== 'undefined'){
        console.error('Crypto WEB') //this was to be sure what I was modifying 
        return { name: 'webCrypto', crypto: webCrypto };
    }
        
    else
        return { name: undefined };
};

can you fix this method of platform detection in the next update please
that would be amazing !

iam not an expert enough to correctly distinguish both platform myself :/

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

1 participant