2

Super noob here with Libsodium so I apologize in advance.

I'm using PHP and working through this example in PHP.

// On Alice's computer:

$alice_box_kp = sodium_crypto_box_keypair();
$alice_sign_kp = sodium_crypto_sign_keypair();

// Split the key for the crypto_box API for ease of use
$alice_box_secretkey = sodium_crypto_box_secretkey($alice_box_kp);
$alice_box_publickey = sodium_crypto_box_publickey($alice_box_kp);

// Split the key for the crypto_sign API for ease of use
$alice_sign_secretkey = sodium_crypto_sign_secretkey($alice_sign_kp);
$alice_sign_publickey = sodium_crypto_sign_publickey($alice_sign_kp);

// On Bob's computer:

$bob_box_kp = sodium_crypto_box_keypair();
$bob_sign_kp = sodium_crypto_sign_keypair();

// Split the key for the crypto_box API for ease of use
$bob_box_secretkey = sodium_crypto_box_secretkey($bob_box_kp);
$bob_box_publickey = sodium_crypto_box_publickey($bob_box_kp);

// Split the key for the crypto_sign API for ease of use
$bob_sign_secretkey = sodium_crypto_sign_secretkey($bob_sign_kp);
$bob_sign_publickey = sodium_crypto_sign_publickey($bob_sign_kp);

How do I get the keys into a file format that I can exchange out of band? On the flip, how can I import the keys or read from the keys?

One key will be on a linux server and the other in a node.js module.

Thanks in advance for your help!

1 Answers1

1

These keys are just binary data, represented as strings in PHP. They are not opaque objects, and they are compatible with all bindings (PHP and NodeJS included).

So, you can just save them to a file (even file_put_contents() will do), or send them through the network as you would save/store an image.

Frank Denis
  • 1,475
  • 9
  • 12
  • 1
    Of course. This is binary data. It's not supposed to be human-readable. If you really want something you can print, you can always convert it from/to hexadecimal or base64. – Frank Denis Dec 11 '17 at 15:32
  • 1
    Thanks, I figured it out with your comment. I thought the garbled text coming out was not correct, but it makes sense if it's binary. – Andrew Derse Dec 11 '17 at 15:52