The programs below will generate an (Edwards) ED25519 curve key pair that can be used with Libsodium's signature function.
The private key (in the documentation named as secret key) is nothing else then a 64 bytes long byte array that should get generated randomly. The public key is a 32 bytes long byte array that needs to get derived from the private key.
My solution is available on all supported frameworks (Java, PHP, C#, NodeJs and within a browser environment).
There are two steps within the program - first you generate a fresh ED25519 key pair and later you derive a public key from the private key.
Usually you pre-generate the key pair and use it later. But what happens when you loose your public key and just have the private key stored in a secure place (see below). For this case it is usefull to derive the public key from the private key.
The short answer is: NO. When you ever should use your private key you need to regenerate a new key pair and publish your public key again so 3rd parties are still been able to verify your [new] signature.
Here are the results (your will differ due to random key creation):
Generate ED25519 private and public and derive public key from private key
privateKey (Base64): sNwj2zo5cSqurF8zjbFOm43/HlGMLuaEfnSMztnctB9a8g9uxHo+n7lDan8EQjAZ/VfWYICtGgHNrYvpBb6GrQ==
publicKey (Base64): WvIPbsR6Pp+5Q2p/BEIwGf1X1mCArRoBza2L6QW+hq0=
derive the publicKey from the privateKey
publicKey (Base64): WvIPbsR6Pp+5Q2p/BEIwGf1X1mCArRoBza2L6QW+hq0=
A last note on ED25519 key pair generation: Especially the private key contains very sensitive data so it need to get protected. Getting the private key from a 3rd party you can sign in the name of him. So what are the typical protection schemes:
a) do not store the key on the device but e.g. an USB-stick. This isn't usable on server systems that need to run without human input
b) store the key in a key store. They are widely available and especially when using a webserver you come into direct contact with the stores. The store itself is protected with a password and the access to the key itself can get protected with an additional, different password.
c) store the key in a password protected zip- or rar- archive. This isn't less usefull as well in automated environments.
Language | available | Online-compiler |
---|---|---|
Java | ✅ | repl.it CpcJavaLibsodiumGenerateEd25519KeyDerivation |
PHP | ✅ | repl.it CpcPhpLibsodiumGenerateEd25519KeyDerivation |
C# | ✅ | # note 1) # dotnetfiddle.net CpcCsharpLibsodiumGenerateEd25519KeyDerivation |
Javascript / NodeJs | ✅ | repl.it CpcNodeJsLibsodiumGenerateEd25519KeyDerivation |
NodeJS CryptoJs | ❌ | use above Javascript / NodeJs solution |
NodeJS Crypto | ❌ | use above Javascript / NodeJs solution |
NodeJS forge | ❌ | use above Javascript / NodeJs solution |
Webcrypto / Browser | ✅ | your browser GenerateEd25519KeysDerivation.html |
Python | ✅ | repl.it CpcPythonLibsodiumGenerateEd25519KeyDerivation |
Dart *2) | ✅ | no online compiler available |
note 1) at the time of writing the online-compiler dotnetfiddle.net does not work properly and claims about less ressources - the code is running correctly but not online, sorry.
*2) you need the external library "flutter_sodium" to run the code (flutter_sodium: ^0.2.0)
Go to Libsodium detached signature of a string.
Last update: Aug. 17th 2021
Back to the main page: readme.md