Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Uncaught SodiumException: scalar and point must be SODIUM_CRYPTO_SCALARMULT_SCALARBYTES

I'm trying to implement ECC Algorithm (x25519) in PHP and Javascript.

I'm using sodium in PHP and crypto in javascript, I kind of new to cryptography and It's about my three days searching and trying out libraries. The sodium_crypto_scalarmult function is throwing this error.

Fatal error:  Uncaught SodiumException: scalar and point must be SODIUM_CRYPTO_SCALARMULT_SCALARBYTES byte

NodeJS/Javascript Code

const { generateKeyPairSync } = require('crypto');

const { publicKey, privateKey } = generateKeyPairSync('x25519', {
   publicKeyEncoding: {
      type: 'spki',
      format: 'der'
   },
   privateKeyEncoding: {
      type: 'pkcs8',
      format: 'der'
   }
});

console.log("Public Key is: ", publicKey)
console.log("The public key value in base64 is: ", publicKey.toString('base64') );

Because I'm just testing right now before implementing it, I just copy and pasted the base64 public key result from javascript to PHP.

PHP

$publicKeyfromJavascript = "";

$bob = sodium_crypto_box_keypair();
$bobPB = sodium_crypto_box_publickey($bob);
$bobsharedKey = sodium_crypto_scalarmult(sodium_crypto_box_secretkey($bob), $publicKeyfromJavascript);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!