You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm creating a standard Electrum ECDH encryption algorithm.
I encounter an error when using the createCipheriv function. However, there are no issues when using Node.js or react-native-crypto.
Could you take a look at the reason? If you need test code, you can refer to the example below. The bsv library is required and can be installed using npm install [email protected].
importcryptofrom"react-native-quick-crypto";importbsvfrom"bsv";constPrivateKey=bsv.PrivateKey;constPublicKey=bsv.PublicKey;constHash=bsv.crypto.Hash;functionelectrumECDHKey(publicKey,privateKey){// Get ECDH Keyconstbuf=PublicKey(publicKey.point.mul(privateKey.bn)).toBuffer();returnHash.sha512(buf);}functionencrypt(message: string,publicKey: string,privateKey?: string){// Prepare keysconstrecvPubkey=newPublicKey(publicKey);// Override ephemeral_key if privateKey is given. This overriding is for traditional ECIES.constephemeralKey=newPrivateKey(privateKey);constecdhKey=electrumECDHKey(recvPubkey,ephemeralKey);constiv=ecdhKey.subarray(0,16);constkeyE=ecdhKey.subarray(16,32);constkeyM=ecdhKey.subarray(32,64);// Encrypt with AES-128-CBCconstcipher=crypto.createCipheriv("aes-128-cbc",keyE,iv);letcrypted=cipher.update(message,"utf8","binary");crypted+=cipher.final("binary");// Build Encrypted MassageconstephemeralPubkey=ephemeralKey.toPublicKey().toBuffer();constencrypted=Buffer.concat([Buffer.from("BIE1"),ephemeralPubkey,Buffer.from(crypted,"binary"),]);consthmac=Hash.sha256hmac(Buffer.from(encrypted),Buffer.from(keyM));returnBuffer.concat([encrypted,hmac]);}
encrypt("Hello World",newPrivateKey().publicKey)
The text was updated successfully, but these errors were encountered:
I'm creating a standard Electrum ECDH encryption algorithm.
I encounter an error when using the createCipheriv function. However, there are no issues when using Node.js or
react-native-crypto
.Could you take a look at the reason? If you need test code, you can refer to the example below. The bsv library is required and can be installed using
npm install [email protected]
.The text was updated successfully, but these errors were encountered: