note 104420 added to function.openssl-public-encrypt

From: Date: Tue, 14 Jun 2011 19:09:01 +0000
Subject: note 104420 added to function.openssl-public-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-180525@lists.php.net to get a copy of this message
The confusion most have seems to be on "mixed $key" The $key is explained in, and mostly the same as the parameter of http://www.php.net/manual/en/function.openssl-pkey-get-public.php It can take the resource $key returned from openssl_pkey_get_public() OR find the value is text and passes the text to openssl_pkey_get_public() to get a valid resource. To better break down rstinnett's example: (and where the flaw is) function EncryptData($source) { $fp=fopen("/etc/httpd/conf/ssl.crt/server.crt","r"); $pub_key_string=fread($fp,8192); fclose($fp); openssl_get_publickey($pub_key); openssl_public_encrypt($source,$crypttext,$pub_key_string); /*this simply passes the string contents of pub_key_string back to be decoded*/ return(base64_encode($crypttext)); } is more efficient: function EncryptData($source) { $fp=fopen("/etc/httpd/conf/ssl.crt/server.crt","r"); $pub_key_string=fread($fp,8192); fclose($fp); $key_resource = openssl_get_publickey($pub_key); openssl_public_encrypt($source,$crypttext, $key_resource ); /*uses the already existing key resource*/ return(base64_encode($crypttext)); } shorter: function EncryptData($source) { $fp=fopen("/etc/httpd/conf/ssl.crt/server.crt","r"); $pub_key=fread($fp,8192); fclose($fp); openssl_public_encrypt($source,$crypttext, $pub_key ); return(base64_encode($crypttext)); } more notes to figure out how to get/use keys are posted on: http://www.php.net/manual/en/function.openssl-pkey-get-public.php ---- Server IP: 69.147.83.197 Probable Submitter: 216.82.251.229 ---- Manual Page -- http://www.php.net/manual/en/function.openssl-public-encrypt.php Edit -- https://master.php.net/note/edit/104420 Del: integrated -- https://master.php.net/note/delete/104420/integrated Del: useless -- https://master.php.net/note/delete/104420/useless Del: bad code -- https://master.php.net/note/delete/104420/bad+code Del: spam -- https://master.php.net/note/delete/104420/spam Del: non-english -- https://master.php.net/note/delete/104420/non-english Del: in docs -- https://master.php.net/note/delete/104420/in+docs Del: other reasons-- https://master.php.net/note/delete/104420 Reject -- https://master.php.net/note/reject/104420 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180525) next »