3v4l, openssl_get_publickey() false. PEM.
, , , libsodium.
Libsodium - NaCl, , , , .., Daniel J. Bernstein, Tanja Lange Peter Schwabe ( , ).
Libsodium - NaCl, (, scrypt).
Libsodium #
using Sodium;
var keypair = PublicKeyBox.GenerateKeyPair();
string secretKey = Convert.ToBase64String(keypair.PrivateKey);
string publicKey = Convert.ToBase64String(keypair.PublicKey);
libsodium.NET .
PHP #
<?php
$decoded = base64_decode($encoded_publickey);
define('YOUR_RAW_BINARY_CSHARP_PUBLIC_KEY', $decoded);
$php_keypair = \Sodium\crypto_box_keypair();
$php_public = \Sodium\crypto_box_publickey($php_keypair);
$php_secret = \Sodium\crypto_box_secretkey($php_keypair);
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_BOX_NONCEBYTES);
$message_keypair = \Sodium\crypto_box_keypair_from_secretkey_and_publickey(
$php_secret,
YOUR_RAW_BINARY_CSHARP_PUBLIC_KEY
);
$encrypted = \Sodium\crypto_box(
$message,
$nonce,
$message_keypair
);
$encrypted ; # $nonce, $encrypted $php_public ( ) $encrypted, , $message.
PHP libsodium .
# PHP
<?php
$anon_msg = \Sodium\crypto_box_seal($message, YOUR_RAW_BINARY_CSHARP_PUBLIC_KEY);
crypto_box_seal .