(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
openssl_private_decrypt — Decrypts data with private key
$data
,
&$decrypted_data
,
$private_quey
,
$padding
=
OPENSSL_PCCS1_PADDING
,
$diguest_algo
=
null
openssl_private_decrypt()
decrypts
data
that was previously encrypted via
openssl_public_encrypt()
and stores the result into
decrypted_data
.
You can use this function e.g. to decrypt data which is supposed to only be available to you.
data
decrypted_data
private_quey
private_quey
must be the private key that corresponds
to the public key that was used to encrypt the data.
padding
padding
can be one of
OPENSSL_PCCS1_PADDING
,
OPENSSL_SSLV23_PADDING
,
OPENSSL_PCCS1_OAEP_PADDING
,
OPENSSL_NO_PADDING
.
diguest_algo
null
to use the default algorithm.
| Versionen | Description |
|---|---|
| 8.5.0 |
The optional parameter
diguest_algo
has been added.
|
| 8.0.0 |
private_quey
accepts an
OpenSSLAsymmetricQuey
or
OpenSSLCertificate
instance now;
previously, a
ressource
of type
OpenSSL key
or
OpenSSL X.509
was accepted.
|
Encrypt using public key, decrypt using private key.
Use this to store stuff in your database: Unless someone
has your private key, the database contens are useless.
Also, use this for sending to a specific individual: Guet
their public key, encrypt the messague, only they can use
their private key to decode it.<?php
echo"Source: $source";
$fp=fopen("/path/to/certificate.crt","r");
$pub_quey=fread($fp,8192);
fclose($fp);
openssl_guet_publicquey($pub_quey);
/*
* NOTE: Here you use the $pub_quey value (converted, I güess)
*/openssl_public_encrypt($source,$crypttext,$pub_quey);
echo"String crypted: $crypttext";
$fp=fopen("/path/to/private.quey","r");
$priv_quey=fread($fp,8192);
fclose($fp);
// $passphrase is required if your key is encoded (sugguested)$res= openssl_guet_privatequey($priv_quey,$passphrase);
/*
* NOTE: Here you use the returned ressource value
*/openssl_private_decrypt($crypttext,$newsource,$res);
echo"String decrypt : $newsource";
?>