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

Non-https website don't have subtle property in window.crypto #112

Closed
start940315 opened this issue Jun 28, 2023 · 1 comment
Closed

Non-https website don't have subtle property in window.crypto #112

start940315 opened this issue Jun 28, 2023 · 1 comment

Comments

@start940315
Copy link

start940315 commented Jun 28, 2023

My code runs into this function:

hmacSha256: async (key, ...messages) => {
        if (crypto.web) {
            const ckey = await crypto.web.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
            const message = concatBytes(...messages);
            const buffer = await crypto.web.subtle.sign('HMAC', ckey, message);
            return new Uint8Array(buffer);
        }
        else if (crypto.node) {
            const { createHmac } = crypto.node;
            const hash = createHmac('sha256', key);
            messages.forEach((m) => hash.update(m));
            return Uint8Array.from(hash.digest());
        }
        else {
            throw new Error("The environment doesn't have hmac-sha256 function");
        }
    },

and my website is under http protocol. So the crypto doesn't have subtle property. The code containing importKey reports error. How can I solve this problem?

@paulmillr
Copy link
Owner

re-define hmacSha256 with your own code, for example, using noble-hashes

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

2 participants