Replies: 1 comment
-
+ // Check for React Native Quick Crypto CryptoKey
+ // RN Quick Crypto CryptoKey has different characteristics
+ if (key && typeof key === 'object') {
+ // React Native Quick Crypto CryptoKey typically has these properties
+ if ('type' in key && 'extractable' in key && 'algorithm' in key && 'usages' in key) {
+ // Additional check for RN Quick Crypto specific implementation
+ if (key.constructor?.name === 'CryptoKey' || key.hasOwnProperty('_handle')) {
+ return true;
+ }
+ }
+ }This should be as simple as adding the proper symbol to the library's CryptoKey instances in react-native-quick-crypto as all web platforms do for their native objects + // Remove trailing '.' from x and y which is added by React Native Quick Crypto
+ const x_clean = x.replace(/\.$/, '');
+ const y_clean = y.replace(/\.$/, '');
const sharedSecret = await ecdhes.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
- parameters = { epk: { x, crv, kty } };
+ parameters = { epk: { x: x_clean, crv, kty } };
if (kty === 'EC')
- parameters.epk.y = y;
+ parameters.epk.y = y_clean;
This seems to be something you need to fix in your subtleImplementation.deriveBits implementation, or react-native-quick-crypto needs to add proper support for the deriveBits operation. - const tag = new Uint8Array((await crypto.subtle.sign('HMAC', macKey, macData)).slice(0, keySize >> 3));
+ const tag = new Uint8Array((crypto.createHmac(hash, macKey)
+ .update(macData)
+ .digest())
+ .slice(0, keySize >> 3));This needs to be fixed by react-native-quick-crypto by adding support for the WebCryptoAPI HMAC algorithm, The rest likewise appears to be just polyfilling the necessary globals and as such, not something jose can do. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was able to get this library working with React Native by assigning global.crypto to React Native Quick Crypto (with a few modifications). I then made some changes to the JOSE library to make it compatible, specifically so it could generate a JWE using alg: ECDH-ES and enc: A128CBC-HS256.
This code was needed in my index.js file to properly set up my global crypto:
Then, I needed to modify the JOSE library which can be done by using the following patch-package file:
Beta Was this translation helpful? Give feedback.
All reactions