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

✨ Add subtle.deriveKey support #456

Open
2 tasks done
bmxam opened this issue Sep 17, 2024 · 2 comments
Open
2 tasks done

✨ Add subtle.deriveKey support #456

bmxam opened this issue Sep 17, 2024 · 2 comments

Comments

@bmxam
Copy link

bmxam commented Sep 17, 2024

What feature or enhancement are you suggesting?

I think it would be great to have support for the subtle.deriveKey function in QuickCrypto.

What Platforms whould this feature/enhancement affect?

iOS, Android

Alternatives/Workarounds

I thinking about moving a full web application built with classic html/css/js to a React Native app (and support multiple plateforms). My app uses encryption a lot and QuickCrypto seems an excellent starting point to translate my current implementation. However, I do need an alternative to crypto.subtle.deriveKey and it is not available (yet ^^) in QuickCrypto.

Additional information

@abdirahmn1
Copy link

👍 for this, it'll be amazing to do:

crypto.subtle.deriveKey(...args);

would love this feature.

@ali-fs
Copy link

ali-fs commented Feb 27, 2025

It's good to have it in react-native-quick-crypto but in the meantime, you can use deriveBits and importKey instead of deriveKey.
Based on deriveBits MDN:

This method is very similar to SubtleCrypto.deriveKey(), except that deriveKey() returns a CryptoKey object rather than an ArrayBuffer. Essentially deriveKey() is composed of deriveBits() followed by importKey().

Here is a sample code:

  const derivedKey = await window.crypto.subtle.deriveKey(
    { name: 'PBKDF2', salt, iterations: 100000, hash: 'SHA-256' },
    baseKey,
    { name: 'AES-GCM', length: 256 },
    true,
    ['encrypt', 'decrypt']
  );

can be replaced with:

  const derivedBits = await quickCrypto.subtle.deriveBits(
    { name: 'PBKDF2', salt, iterations: 100000, hash: 'SHA-256' },
    baseKey,
    256
  );
  const derivedKey = await quickCrypto.subtle.importKey(
    'raw', 
    derivedBits,
    { name: 'AES-GCM', length: 256 },
    true,
    ['encrypt', 'decrypt']
  );

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