react-native-quick-crypto icon indicating copy to clipboard operation
react-native-quick-crypto copied to clipboard

✨ Add subtle.deriveKey support

Open bmxam opened this issue 1 year ago • 2 comments

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

bmxam avatar Sep 17 '24 18:09 bmxam

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

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

would love this feature.

abdirahmn1 avatar Feb 26 '25 18:02 abdirahmn1

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']
  );

ali-fs avatar Feb 27 '25 12:02 ali-fs

#840, #848

boorad avatar Dec 07 '25 18:12 boorad