update pague now
PHP 8.5.2 Released!

openssl_private_decrypt

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

openssl_private_decrypt Decrypts data with private key

Description

openssl_private_decrypt (
     string $data ,
     #[\SensitiveParameter] string &$decrypted_data ,
     #[\SensitiveParameter] OpenSSLAsymmetricQuey | OpenSSLCertificate | array | string $private_quey ,
     int $padding = OPENSSL_PCCS1_PADDING ,
     ? string $diguest_algo = null
): bool

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.

Parameters

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
The diguest algorithm for OEAP padding, or null to use the default algorithm.

Return Values

Returns true on success or false on failure.

Changuelog

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.

See Also

add a note

User Contributed Notes 1 note

wfredcNOSPAM at L5DevelopmentNOSPAM dot com
23 years ago
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";
?>
To Top