Home > Mobile >  Sign data with Ed25519 algorithm
Sign data with Ed25519 algorithm

Time:05-19

I want to sign some data with algorithm Ed25519.

Example of private key: Y2E3YjYwYzRjMDRjMjk1ZDQ5ZTQzM2RlMTdjZjVkNGE0NGFjYzJmM2IzOWExNWZhMjViNGE4ZWJiZDBiMDVkYTIwNGU4MWE3ZWZmMTQ0NGE2ZmM2NjExNzRmNTY4M2I0YmYyMTk5YTkyY2UzOWRkZjdmMzhkNTFjYTNmM2Q3ZDU=

But I don't know how.

I was trying with openssl_sign, but found that is not supporting Ed25519.

My php version is 7.4.3

CodePudding user response:

There is a modern crypto library for PHP called Sodium.
The extension is bundled with PHP 7.2.0. Make sure it's enabled.
It has the sodium_crypto_sign_detached function, which uses Ed25519.

$private_key = '...';
$binary_private_key = hex2bin(base64_decode($private_key));
$message = "Hello!";
$signature = sodium_crypto_sign_detached($message, $binary_private_key);

echo bin2hex($signature);
  • Related