troubleshooting Question

Help needed to understand PHP Libsodium and how to export keys.

Avatar of Carlos Llanos
Carlos LlanosFlag for United States of America asked on
PHP* Cryptography
7 Comments1 Solution621 ViewsLast Modified:
I'm trying to implement a solution using PHP and Libsodium.

I'm working off of this example:

// 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);

// Optionally, you can reassemble a keypair string from a secret key and 
// public key pair:

$keypair = sodium_crypto_box_keypair_from_secretkey_and_publickey(
    $alice_box_secretkey,
    $alice_box_publickey
);

Basically, stuck on the part where I need to export the public keys so I can share them with another user.

Server A has a private and public key generating in code, but I don't know how to export it.
Server B has a private and public key generating in code, but I don't know how to export it.

Once exported, I will need to know how to import the keys so I can decrypt the messages.

I used to use open_ssl library which was straightforward, but my company desire to use the libsodium libraries now and I can't seem to find any functions to export the keys.
ASKER CERTIFIED SOLUTION
Carlos Llanos
IT Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros