如何使用 PHP 导出 Libsoidum 密钥
How to export Libsoidum keys using PHP
这里是 Libsodium 的超级菜鸟所以我提前道歉。
我正在使用 PHP 并在 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);
如何将密钥转换为可以带外交换的文件格式?
另一方面,如何导入密钥或从密钥中读取?
一个密钥将在 linux 服务器上,另一个在 node.js 模块中。
在此先感谢您的帮助!
这些键只是二进制数据,在PHP中表示为字符串。它们不是不透明对象,并且与所有绑定兼容(包括 PHP 和 NodeJS)。
因此,您可以将它们保存到一个文件中(即使 file_put_contents()
也可以),或者像 save/store 图片一样通过网络发送它们。
这里是 Libsodium 的超级菜鸟所以我提前道歉。
我正在使用 PHP 并在 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);
如何将密钥转换为可以带外交换的文件格式? 另一方面,如何导入密钥或从密钥中读取?
一个密钥将在 linux 服务器上,另一个在 node.js 模块中。
在此先感谢您的帮助!
这些键只是二进制数据,在PHP中表示为字符串。它们不是不透明对象,并且与所有绑定兼容(包括 PHP 和 NodeJS)。
因此,您可以将它们保存到一个文件中(即使 file_put_contents()
也可以),或者像 save/store 图片一样通过网络发送它们。