0

Im running the below code snippet and I'm getting the error TypeError: Cannot read property 'elGamal' of undefined

    var sjcl = require("sjcl");
    var keys = sjcl.ecc.elGamal.publicKey(); //choose a stronger/weaker curve

    var pubkem = keys.pub.kem(); //KEM is Key Encapsulation Mechanism
    var pubkey = pubkem.key;
    var seckey = keys.sec.unkem(pubkem.tag); //tag is used to derive the secret (private) key

    var plain = "hello world!";
    var cipher = sjcl.encrypt(pubkey, plain); //defaults to AES
    var result = sjcl.decrypt(seckey, cipher);

    console.log(plain === result); //true
Medi
  • 1,026
  • 2
  • 9
  • 12
  • Give it a try with `require('sjcl-complete')`. – Topaco Feb 06 '21 at 14:35
  • It gave me this error **TypeError: Cannot read property 'r' of undefined at Object.publicKey (/home/runner/EquatorialAlphanumericExecutable/node_modules/sjcl-complete/sjcl.js:124:62)** – Medi Feb 06 '21 at 14:52
  • 2
    Try using e.g. `var keys = sjcl.ecc.elGamal.generateKeys(sjcl.ecc.curves.k256);` – Topaco Feb 06 '21 at 14:58
  • It worked. you made my day, thank you @Topaco. – Medi Feb 06 '21 at 15:01

0 Answers0