CakeFest 2024: The Official CakePHP Conference

openssl_pkcs7_decrypt

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

openssl_pkcs7_decryptS/MIME şifreli bir iletinin şifresini çözer

Açıklama

openssl_pkcs7_decrypt(
    string $girdi_dosyası,
    string $çıktı_dosyası,
    OpenSSLCertificate|string $sertifika,
    OpenSSLAsymmetricKey|OpenSSLCertificate|array|string|null $gizli_anahtar = null
): bool

Şifreli iletiyi girdi_dosyası'ndan okur, sertifika ile belirtilen sertifikaları ve gizli_anahtar ile belirtilen gizli anahtarı kullanarak iletinin şifresini çözer ve sonucu çıktı_dosyası'na kaydeder.

Bağımsız Değişkenler

girdi_dosyası

çıktı_dosyası

Şifresi çözülen iletinin kaydedileceği dosyanın yolu.

sertifika

gizli_anahtar

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 gizli_anahtar artık OpenSSLAsymmetricKey veya OpenSSLCertificate örneği kabul ediyor; evvelce, OpenSSL key veya OpenSSL X.509 CSR özkaynağı kabul edilirdi.

Örnekler

Örnek 1 - openssl_pkcs7_decrypt() örneği

<?php
// $sert ve $anahtar kişisel sertifikanızı ve gizli anahtarınızı içersin.
$şifreli = "encrypted.msg"; // Şifreli iletinin bulunduğu dosya
$şifresiz = "decrypted.msg"; // Şifresiz iletinin yazılacağı dosya

if (openssl_pkcs7_decrypt($şifreli, $şifresiz, $sert, $anahtar)) {
echo
"Şifre çözüldü!";
} else {
echo
"Şifre çözülemedi!";
}
?>

add a note

User Contributed Notes 1 note

up
1
oliver at anonsphere dot com
12 years ago
If you want to decrypt a received email, keep in mind that you need the full encrypted message including the mime header.

<?php

// Get the full message
$encrypted = imap_fetchmime($stream, $msg_number, "1", FT_UID);
$encrypted .= imap_fetchbody($stream, $msg_number, "1", FT_UID);

// Write the needed temporary files
$infile = tempnam("", "enc");
file_put_contents($infile, $encrypted);
$outfile = tempnam("", "dec");

// The certification stuff
$public = file_get_contents("/path/to/your/cert.pem");
$private = array(file_get_contents("/path/to/your/cert.pem"), "password");

// Ready? Go!
if(openssl_pkcs7_decrypt($infile, $outfile, $public, $private))
{
// Decryption successful
echo file_get_contents($outfile);
}
else
{
// Decryption failed
echo "Oh oh! Decryption failed!";
}

// Remove the temp files
@unlink($infile);
@
unlink($outfile);

?>
To Top