$configArgs = array( 'config' => 'C:\xampp\apache\bin\openssl.cnf', "digest_alg" => "sha512", "private_key_bits" => 4096, "private_key_type" => OPENSSL_KEYTYPE_RSA, ); // Create the private and public key $res = openssl_pkey_new($configArgs); // Extract the private key from $res to $privKey openssl_pkey_export($res, $privKey, null, $configArgs); // Extract the public key from $res to $pubKey $pubKey = openssl_pkey_get_details($res); $pubKey = $pubKey["key"]; $data = 'plaintext data goes here'; // Encrypt the data to $encrypted using the public key openssl_public_encrypt($data, $encrypted, $pubKey); // Decrypt the data using the private key and store the results in $decrypted openssl_private_decrypt($encrypted, $decrypted, $privKey); //echo $decrypted; var_dump($decrypted);exit;
php公钥加密和私钥解密
最新推荐文章于 2024-04-20 11:32:25 发布