0

I am trying to convert the following Kotlin code into NodeJS so that the Kotlin application can also communicate with the server. I unfortunately notice within CryptoJS that I can't get this to function fully. How can I use the function getSharedSecret and getAESKey in nodejs to get this script working?

Kotlin code: Kotlin ECC Encryption

This is my nodejs code so far - which is nothing special by the way:

        var crypto = require('crypto');
        const keyPairA = crypto.createECDH('secp521r1'); keyPairA.generateKeys();
        const keyPairB = crypto.createECDH('secp521r1'); keyPairB.generateKeys();
        const rawPrivateA = keyPairA.getPrivateKey('hex');
        const rawPublicA = keyPairA.getPublicKey('hex', 'uncompressed');
        const rawPrivateB = keyPairB.getPrivateKey('hex'); 
        const rawPublicB = keyPairB.getPublicKey('hex', 'uncompressed');
    
        console.log('rawPrivateA',rawPrivateA) console.log('rawPublicA',rawPublicA) console.log('---')
        console.log('rawPrivateB',rawPrivateB) 
        console.log('rawPublicB',rawPublicB) 
        console.log('------------')

I've tried the derive function within nodejs but it keeps crashing the app.

Who can point me in the right direction for this?

Ben Jerry
  • 79
  • 1
  • 5
  • 1
    Your code covers only a fraction of the needed functionality. I recommend you to focus on the shared secret part (`getSharedSecret()`, `getAESKey()`) or on the AES/GCM part (`encrypt()`, `decrypt()`). Try the corresponding ports and if you get stuck, post your code and describe the problem. Useful are also (non-productive) sample data. – Topaco Aug 01 '23 at 08:41

0 Answers0