php - [function.openssl-public-encrypt]: key parameter is not a valid public key -



php - [function.openssl-public-encrypt]: key parameter is not a valid public key -

long time listener/first time caller

i have set test page follows

<form action="" method="post"> <input type="text" name="value" width="20" max="30" value=""/> <input type="submit" value="go"/> </form>

with php encrypt post info "value" , store in variable so

$pubkey = openssl_pkey_get_public(".../public.pem"); openssl_public_encrypt($_post["value"], $var, $pubkey); echo $var;

also have tried

$publickey = ".../public.pem"; $plaintext = $_post['value']; openssl_public_encrypt($plaintext, $encrypted, $publickey); echo $encrypted;

keep getting error

warning: openssl_public_encrypt() [function.openssl-public-encrypt]: key parameter not valid public key

i created keys openssl using:

# generate 1024 bit rsa private key, inquire passphrase encrypt , save file openssl genrsa -des3 -out /path/to/privatekey 1024 # generate public key private key , save file openssl rsa -in /path/to/privatekey -pubout -out /path/to/publickey

from website http://andytson.com/blog/2009/07/php-public-key-cryptography-using-openssl/

also tried creating key method:

openssl req \ -x509 -nodes -days 365 \ -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

still same error. sorry whole encryption cryptic me. not familiar openssl code examples great.

your paths appear incorrect:

$pubkey = openssl_pkey_get_public(".../public.pem");

and

$publickey = ".../public.pem";

should

$publickey = "../public.pem"; $pubkey = openssl_pkey_get_public("../public.pem");

if .pem file in parent directory, or:

$publickey = "./public.pem"; $pubkey = openssl_pkey_get_public("./public.pem");

if .pem file in current working directory. alternately, can utilize absolute paths sure grabbing right file.

php html openssl

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -