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

90
Views
TweetNaCl.js Public-key signatures example err

I want to use ed25519 to sign my message. And I found TweetNaCl.js which has the Signatures method to achieve my goal.

By referencing TweetNaCl.js minimal Public-key signatures example and official document-Signatures, here is my test code codesandbox.

  const keyPair = nacl.sign.keyPair();
  const secretKey = keyPair.secretKey;
  const publicKey = keyPair.publicKey;
  const secretKeyB64 = encodeBase64(secretKey);
  const publicKeyB64 = encodeBase64(publicKey);
  console.log("secretKeyB64", secretKeyB64);
  console.log("publicKeyB64", publicKeyB64);

  const msgStr = "My unencrypted message";
  const msg = decodeUTF8(msgStr);
  const signature = nacl.sign(msg, secretKey);
  const signatureB64 = encodeBase64(signature);
  console.log("signatureB64", signatureB64);
  const verifiedMsg = nacl.sign.open(signature, publicKey);
  console.log(encodeUTF8(verifiedMsg));

The encodeUTF8(verifiedMsg)'s console log seems no problem and is as same as msgStr.

But I notice that when I put the publicKeyB64, signatureB64, and msgStr to the tweetnacl.js' example page(Public-key signatures) to verify it, it responds error Bad signature length: must be 64 bytes.

If I put the secretKeyB64 into the example sign page, and click "Sign", the Signature seems shorter than what I created from Codesandbox's code.

Is there anything that I missed?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figure out this problem 20 minutes later... Thanks for the StackOverflow ?!!

I console log the signature and find its length is over 64. After I reviewed the Signatures, I found another method nacl.sign.detached(message, secretKey) and its length was 64!!!

After encodeBase64 and put it to the tweetnacl.js' example page(Public-key signatures) to verify it, it works!!

about 4 years ago · Juan Pablo Isaza Report
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!