Created
May 23, 2019 20:32
-
-
Save whatthefork/dfded56e713241d8109834f5147eb05a to your computer and use it in GitHub Desktop.
Sodium - Generate keypair for signing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
SODIUM CRYPTO | |
GENERATE NEW KEY PAIR FOR PACKAGE SIGNING | |
You can use this to create a signing keypair and use it to sign plugins and themes for WordPress 5.2 and newer: | |
*/ | |
function generate_new_key_pair() { | |
// Generate new key pair | |
$my_signing_key_pair = sodium_crypto_sign_keypair(); | |
// Extract secret key | |
$secret_key = sodium_crypto_sign_secretkey( $my_signing_key_pair ); | |
$secret_key_base64 = base64_encode( $secret_key ); | |
var_dump( $secret_key_base64 ); | |
// Extract public key | |
$public_key = sodium_crypto_sign_publickey($mySigningKeypair); | |
$public_key_base64 = base64_encode( $public_key ); | |
var_dump( $public_key_base64 ); | |
// ------- This is to test the keys: -------- | |
$message = 'authenticate me'; | |
// decode secret key | |
$secretKey = base64_decode( $secret_key_base64 ); | |
// Sign the message, using the secret key | |
$signature = sodium_crypto_sign_detached( $message, $secretKey ); | |
// Decode public key | |
$publicKey = base64_decode( $public_key_base64 ); | |
$res = sodium_crypto_sign_verify_detached( $signature, $message, $publicKey ); | |
var_dump ($res ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment