note 104610 added to function.openssl-open
| From: | sdc at osu1 dot php dot net | Date: | Sat, 25 Jun 2011 21:31:06 +0000 |
| Subject: | note 104610 added to function.openssl-open | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180951@lists.php.net to get a copy of this message | ||
PHP compiled without OpenSSL support? Here's how you can call the openssl command-line utility
to achieve the same goal:
<?php
// $sealed and $env_key are assumed to contain the sealed data
// and our envelope key, both given to us by the sealer.
// specify private key file and passphrase
$pkey_file='key.pem';
$pkey_pp='netsvc';
// call openssl to decrypt envelope key
$ph=proc_open('openssl rsautl -decrypt -inkey '.
escapeshellarg($pkey_file).' -passin fd:3',array(
0 => array('pipe','r'), // stdin < envelope key
1 => array('pipe','w'), // stdout > decoded envelope key
2 => STDERR,
3 => array('pipe','r'), // < passphrase
),$pipes);
// write envelope key
fwrite($pipes[0],$env_key);
fclose($pipes[0]);
// write private key passphrase
fwrite($pipes[3],$pkey_pp);
fclose($pipes[3]);
// read decoded key, convert to hexadecimal
$env_key='';
while(!feof($pipes[1])){
$env_key.=sprintf("%02x",ord(fgetc($pipes[1])));
}
fclose($pipes[1]);
if($xc=proc_close($ph)){
echo "Exit code: $xc\n";
}
// call openssl to decryp
$ph=proc_open('openssl rc4 -d -iv 0 -K '.$env_key,array(
0 => array('pipe','r'), // stdin < sealed data
1 => array('pipe','w'), // stdout > opened data
2 => STDERR,
),$pipes);
// write sealed data
fwrite($pipes[0],$sealed);
fclose($pipes[0]);
// read opened data
//$open=stream_get_contents($pipes[1]);
$open='';
while(!feof($pipes[1])){
$open.=fgets($pipes[1]);
}
fclose($pipes[1]);
if($xc=proc_close($ph)){
echo "Exit code: $xc\n";
}
// display the decrypted data
echo $open;
?>
----
Server IP: 192.41.42.26
Probable Submitter: 24.252.59.47
----
Manual Page -- http://www.php.net/manual/en/function.openssl-open.php
Edit -- https://master.php.net/note/edit/104610
Del: integrated -- https://master.php.net/note/delete/104610/integrated
Del: useless -- https://master.php.net/note/delete/104610/useless
Del: bad code -- https://master.php.net/note/delete/104610/bad+code
Del: spam -- https://master.php.net/note/delete/104610/spam
Del: non-english -- https://master.php.net/note/delete/104610/non-english
Del: in docs -- https://master.php.net/note/delete/104610/in+docs
Del: other reasons-- https://master.php.net/note/delete/104610
Reject -- https://master.php.net/note/reject/104610
Search -- https://master.php.net/manage/user-notes.php