@asac wrote:
Hello guys,
I’m currently developing an Ionic App that needs to use some crypto stuff. I used npm to install some packages like
js-crypto-aes
,js-crypto-ec
, …
I created a folderscritps
insidesrc
on which I added all my .ts files that use crypto. When I import the functions from those files to myhome.page.ts
, the editor (vscode) detects all the functions and everything goes well. When i run the scripts with ts-node or tsc, it all goes well.
However, when i start the server I can’t use my crypto functions, because Ionic can’t use the packages properly. It gives me errors like:Error: FailedBothNativeAndPureJSEnvs: UnsupportedJWKType.
Can anyone here help me, please ?
Here is a part of the code:import hkdf from 'js-crypto-hkdf'; import ec from 'js-crypto-ec'; import keyutil from 'js-crypto-key-utils'; import aes from 'js-crypto-aes'; import hmac from 'js-crypto-hmac'; import {WebApi,Oidc,TransferMethods,NfcOptions,BleOptions,WifiOptions,Security,SessionData, SessionEstablishment} from './deviceEngagement'; import {KeyTypes, KeyCrv, HeaderParameters} from './cose_parameters'; import { encryptEc } from './jscu/packages/js-crypto-utils/dist/pkcec'; async function encrypt_msg(msg,publicKey, iv, salt, { privateKey, hash, encrypt='AES-GCM', keyLength=32, info=''}) { hash = 'SHA-256' const sharedSecret = await ec.deriveSecret(publicKey, privateKey); const hkdfOutput = await hkdf.compute(sharedSecret, hash, keyLength, info, salt); // use HKDF for key derivation const aad = new TextEncoder().encode(''); const aditional_data = await hmac.compute(sharedSecret, aad, hash); // authenticate message let data; if(encrypt =='AES-GCM') { data = await aes.encrypt(msg, hkdfOutput.key, {name: encrypt, iv, additionalData: aditional_data, tagLength: 16}); // no specification of tagLength and additionalData return {data, salt: hkdfOutput.salt, iv}; } };
The error occurs when I call the encrypt_msg function, and it brokes on the first line it calls the library: const
sharedSecret = await ec.deriveSecret(publicKey, privateKey);
Again, when I run the script with ts-node there is no problems.
Posts: 1
Participants: 1