php


PHP - Decrypt - OpenSSL


The encryption is done correctly, but when to use openssl_get_privatekey and save in $key_resource, this has a null value, so it throws the error: openssl_private_decrypt(): key parameter is not a valid private key in ...
function encriptarDatos($datos){
$fp=fopen("public.key","r");
$pub_key=fread($fp,8192);
fclose($fp);
$key_resource = openssl_get_publickey($pub_key);
openssl_public_encrypt($datos,$encriptado,$key_resource );
/*uses the already existing key resource*/
return(base64_encode($encriptado));
}
function desencriptarDatos($datos){
$fp=fopen("private.key","r");
$priv_key=fread($fp,8192);
fclose($fp);
echo "priv_key: $priv_key <br/><br/>";
$key_resource = openssl_get_privatekey($priv_key);
echo "key_resourse: $key_resource";
openssl_private_decrypt($datos,$desencriptado,$key_resource);
/*uses the already existing key resource*/
return(base64_encode($desencriptado));
}
Then I changed it:
$fp=fopen("private.key","r");
$priv_key=fread($fp,8192);
fclose($fp);
openssl_private_decrypt($datos, $desencriptado, openssl_pkey_get_private($priv_key, "phrase"));
/*uses the already existing key resource*/
return(base64_encode($desencriptado));
but the result is also null

Related Links

Laravel protected attributes and Mutators
Merge Insert Into TABLE with an PHP ARRAY and for loop
cURL Login and set sessions
How to remove quotes from each element in a javascript array containing JSON encoded html strings returned from a mysql database with php
Symfony 2.x with FOS-Userbundle: Controll all Sessions
Laravel 5.2 add params to url
My code does not save the data form
SELECT INTO OUTFILE in an INSERT MySQL Query
laravel5.3 generate download (.txt) on the fly
how to pass through OAuth and how to get json data
500 (Internal Server Error) using jQuery $.post with CodeIgniter
laravel - show name instead of id in a url using routing
Composer - autoload classes in CodeIgniter outside vendor folder
Wrong response from the webhook: 400 Bad Request
Laravel eloquent compare custom value
Stuck trying to insert data into mySQL database [duplicate]

Categories

HOME
mpdf
shinyapps
stacktrace.js
apk
vsts-build
tabs
fogbugz
dependencies
hyperledger
anchor
jpa-criteria
gtk
reportviewer
lc3
parsley.js
tiff
clish
pm2
cuba-platform
sql-injection
django-rq
supervisord
vmware-workstation
rest-assured
pickle
gmp
animated-gif
pyopencl
software-packaging
password-generator
fstar
iwebbrowser2
openbr
autodesk-model-derivative
publishing
plantuml
caesar-cipher
sql-execution-plan
kendo-listview
dreamfactory
xerces-c
runtimeexception
twilio-php
android-n
assemblies
praat
system-on-chip
moinmoin
react-intl
adblock
cordova-ios
datediff
test-data
streamwriter
mathjs
system.web.optimization
bilinear-interpolation
traversable
between
bbc-micro
yii2-model
powerpoint-2013
distributed-cache
ioctl
gdl
espresso
supercomputers
cache-manifest
ampersand
nhibernate-criteria
microsoft-expression-web
adhoc-polymorphism
rubber
window-resize
mobile-country-code
aho-corasick
csslint
senchatouch-2.4
sqlbindparameter
lsa
hyphen
hints
wndproc
getopt-long
prototypal-inheritance
background-repeat
will-paginate
winsxs
page-curl
fragment-identifier
digiflow
3des
odac
rational-unified-process
google-translator-toolkit
ppc
downcasting
service-factory

Resources

Encrypt Message