decrypting RSA attachments from mail
Posted: Sun Feb 28, 2010 11:32 am
I'm trying to decrypt email attachments that use an RSA keyy. Without the encryption, I can read the email and the attachments but when I throw in the encryption, I can't seem to decrypt them. I can read the encrypted in Exchange just not in my php scripts
Thanks for any help!!
Acc427us
Here is the PHP function I'm using:
Acc427us
Here is the PHP function I'm using:
Code: Select all
<?php
function DeCrypt($dataStr) {
$decoded_source = base64_decode($dataStr);
$cert = 'mycert.pem';
$pass = 'mypasswd';
$fp = fopen($cert,'r');
$priv_key = fread($fp,8192);
fclose($fp);
$res = $privatekey = openssl_pkey_get_private ($priv_key, $pass);
if ($res) {
#openssl_private_decrypt(base64_decode($dataStr), $output, $privatekey);
$resout = openssl_private_decrypt($decoded_source, $output, $privatekey);
if ($resout) {echo "RESOUT:" . $resout . "\r\n";}
echo "OUTPUT:" . $output . "\r\n";
return $output;
}
else { return 'Key Invalid'; }
}
?>