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

✨ Add support for `subtle.importKey` and `subtle.sign` with HMAC

Open Ldoppea opened this issue 9 months ago • 8 comments

What feature or enhancement are you suggesting?

Hi,

First, thanks for maintaining this library.

My team would like to use RNQC in our mobile app. The best candidate is 0.x version but there are lacking 2 methods for our login workflow: sublte.importKey and subtle.sign with HMAC.

Here is the list of all methods we use:

Algorithm supported 0.x supported 1.x
crypto.getRandomValues(array)
crypto.subtle.digest('SHA-256', data) SHA-256
crypto.subtle.generateKey('RSA-OAEP' ... ) RSA-OAEP
crypto.subtle.importKey('raw' ... 'PBKDF2' ...) raw PBKDF2
crypto.subtle.importKey('raw' ... 'AES-CBC' ...) raw AES-CBC
crypto.subtle.importKey('raw' ... 'HMAC'... 'SHA-256' ...) raw HMAC
crypto.subtle.exportKey('spki' ...) (RSA-AOEP) spki RSA-AOEP
crypto.subtle.exportKey('pkcs8' ...) (RSA-AOEP) pkcs8 RSA-AOEP
crypto.subtle.deriveBits('PBKDF2' ... 'SHA-256' ...) PBKDF2
crypto.subtle.encrypt('AES-CBC' ...) AES-CBC
crypto.subtle.sign('HMAC' ... 'SHA-256' ...) HMAC

Are there any plan to implement missing methods?

With this compatibility array, I imagine that the "easiest" solution would be to implement them in 0.x. But if there are plans to improve the 1.x support in a short term we can wait.

I'm not sure how to help for this. My direct team has only a few knowledge on cryptography, but we can learn and try to do a PR on 0.x if you don't plan to implement it on your side. However if you have a first idea on the complexity of such a task this would help us to negociate some time to do it.

Thanks

What Platforms whould this feature/enhancement affect?

iOS, Android

Alternatives/Workarounds

For now we are using a bridge to a hidden webview that execute all the crypto methods and return them to RN.

This works well but it is way slower. Especially this impacts the app's boot time because initializing a webview can take hundred of milliseconds.

Additional information

Ldoppea avatar Mar 17 '25 13:03 Ldoppea

also curious here about implementing more functions not yet covered. I'd really appreciate functionality to pull off crypto.subtle.importKey for pkcs8, looking through the code myself to see if I can write a PR but I'm not sure I'll have any real time to sink into this at the moment. would be great for a quick solution that doesn't require react-native-webview-crypto

arron-taylor avatar Mar 26 '25 15:03 arron-taylor

@boorad can we close this issue?

renanmav avatar Mar 28 '25 00:03 renanmav

@boorad can we close this issue?

no

boorad avatar Mar 28 '25 01:03 boorad

@DavideSegullo any progress on subtle.sign() for HMAC?

boorad avatar Apr 08 '25 13:04 boorad

@DavideSegullo any progress on subtle.sign() for HMAC?

Not yet sorry, maybe end of this week I'll try to work on it!

DavideSegullo avatar Apr 08 '25 14:04 DavideSegullo

@DavideSegullo any progress on subtle.sign() for HMAC?

Not yet sorry, maybe end of this week I'll try to work on it!

Just wanted to check if there was any update here or expected timeline on when the subtle.sign() for HMAC will be implemented. Thanks!

mbirnhak avatar Apr 13 '25 15:04 mbirnhak

hey @mbirnhak I started on working on it, but I don't have a PR ready I'll try to complete it in the next days

DavideSegullo avatar Apr 15 '25 11:04 DavideSegullo

@DavideSegullo any progress on subtle.sign() for HMAC?

Not yet sorry, maybe end of this week I'll try to work on it!

Just wanted to check if there was any update here or expected timeline on when the subtle.sign() for HMAC will be implemented. Thanks!

I tried something, but it doesn't work yet :( it crash on c++ side, I need to investigate it, let's see if I can fix it

DavideSegullo avatar Apr 23 '25 15:04 DavideSegullo

I think #823 implements subtle.importKey() for HMAC. Check it out and let me know...

boorad avatar Nov 26 '25 03:11 boorad

#842 implements subtle.sign() for HMAC

boorad avatar Dec 05 '25 05:12 boorad