note 111841 added to function.openssl-private-decrypt
| From: | ittasks at gmail dot com | Date: | Wed, 03 Apr 2013 22:17:49 +0000 |
| Subject: | note 111841 added to function.openssl-private-decrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194309@lists.php.net to get a copy of this message | ||
//if you want to encrypt data without knowing the password so it only be accessible to admin (like
storing CC data) - here is one of the ways to do that.
$fnm="test";//path to the file name (.key and .pem)
echo "<form method=post
action=".$_SERVER['PHP_SELF']."><table>";
$pass=$_REQUEST['pass'];
$msg=$_REQUEST['msg'];
$genkey=((isset($_REQUEST['go']))?intval("0".$_REQUEST['genkey']):1);
echo "<tr><td>Admin Password :</td><td><input type=text name=pass
value=\"$pass\"></td></tr>\n";
echo "<tr><td>Generate New Keys?</td><td><input type=checkbox
name=genkey value=1".($genkey?" checked":"").">
Yes</td></tr>\n";
echo "<tr><td colspan=2 align=left>Message:<br><textarea cols=50
name=msg>$msg</textarea></td></tr>\n";
echo "<tr><td colspan=2><input type=submit name='go'
value='Go'></td></tr>";
echo "</table></form>";
if($_REQUEST['go']=='Go')
{
$pass=$_REQUEST['pass'];
$msg=$_REQUEST['msg'];
//this you have to only run once ...
if($genkey)
{
echo "<br>generating public/private keys using supplied password...";
exec("openssl req -x509 -passout pass:$pass -newkey rsa:1024 -keyout $fnm.key -out
$fnm.pem -subj
\"/C=US/ST=California/L=Remote/O=blabla/OU=blabla/CN=user/emailAddress=user@domain.com\"");
}
// or in case if you want to change admin password you need to generate new keys with new
password
// and run a script that will take all encrypted data from database, decrypt with old private
key and re-encrypt with new private key
echo "<br>Source file: $fnm.pem";
openssl_public_encrypt(urlencode($msg), $encbinary, "file://$fnm.pem"); //no password
usage here
$encmsg=base64_encode($encbinary); //ready to be send or stored in DB
echo "<br><br>Encrypted message:<pre>$encmsg</pre>";
echo "<br><br>Decrypting using private key with password...<br>";
if(($prvkey = openssl_pkey_get_private("file://$fnm.key",$pass))===false)
echo "<br><b style='color:red'>Password is incorrect,
aborting.</b>";
else
{
openssl_private_decrypt(base64_decode($encmsg),$decmsg,$prvkey);
echo "<br>Decrypted message:<br>".urldecode($decmsg);
}
}
----
Server IP: 69.147.83.199
Probable Submitter: 69.165.158.28
----
Manual Page -- http://php.net/manual/en/function.openssl-private-decrypt.php
Edit -- https://master.php.net/note/edit/111841
Del: integrated -- https://master.php.net/note/delete/111841/integrated
Del: useless -- https://master.php.net/note/delete/111841/useless
Del: bad code -- https://master.php.net/note/delete/111841/bad+code
Del: spam -- https://master.php.net/note/delete/111841/spam
Del: non-english -- https://master.php.net/note/delete/111841/non-english
Del: in docs -- https://master.php.net/note/delete/111841/in+docs
Del: other reasons-- https://master.php.net/note/delete/111841
Reject -- https://master.php.net/note/reject/111841
Search -- https://master.php.net/manage/user-notes.php