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ı,
    mixed $alıcı_sertifikaları,
    mixed $alıcı_anahtarı = ?
): bool

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

Değiştirgeler

girdi_dosyası

çıktı_dosyası

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

alıcı_sertifikaları

alıcı_anahtarı

Dönen Değerler

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

Ö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 add a note

User Contributed Notes 1 note

up
3
oliver at anonsphere dot com
13 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