Secure Laravel OpenSSL Public Key/Private Key Encryption Library.
- Php Openssl Generate Public Key West
- Php Openssl Generate Public Key From Private Key
- Php Openssl Generate Public Key In Linux
- Php Openssl Generate Rsa Key Pair
- Php Openssl Generate Public Key In Command Prompt
Introduction
OpenSSL Encryption is laravel public/private key pair encryption package. Which allow you to generate public/private key and encrypt and decrypt data with that public/private key.
You want to send/receive secure message to your friends. Then you have to generate public/private key and send the public key to your friends. Now one of your friends encrypt the message with your given public key and send it to you. You receive the message and decrypt the message with your private key.
If any attacker found the message but the attacker could not decrypt it without your private key. So don't share your private key with anyone.
Install (Laravel)
Install via composer
I want to generate an RSA public public key file using openssl (or other tools) having public modulus and exponent, so i can use it later to encrypt files i have this: the modulus: '.
The package is auto-discovered and registered by default, but if you want to register it yourself:
Add service provider to
config/app.php
in providers
section.Add alias to
config/app.php
in alias
section.To publish the config, run the vendor publish command:
Usage
Php Openssl Generate Public Key West
To generate public/private key run the following artisan command :
After generating the key you need to set your public/private key path to
config/openss.php
and passphrase (if you set passphrase while generating key).Encrypt Data:
Php Openssl Generate Public Key From Private Key
Decrypt Data:
Upcoming Feature
Encrypt and decrypt with multiple public/private key.
Php Openssl Generate Public Key In Linux
License
Php Openssl Generate Rsa Key Pair
OpenSSL Encryption is open-sourced software licensed under the MIT license
Php Openssl Generate Public Key In Command Prompt
length of the data < length of the private key ..so i divided the message while taking it,put a ':::'.then again encrpt it. look at the pgm to get an idea about this..
<?php
class cry
{
# generate a 1024 bit rsa private key, ask for a passphrase to encrypt it and save to file
//openssl genrsa -des3 -out /path/to/privatekey 1024
# generate the public key for the private key and save to file
//openssl rsa -in /path/to/privatekey -pubout -out /path/to/publickey
//programatically using php-openssll
//This will call while registration
function gen_cert($userid)
{
$dn = array('countryName' => 'XX', 'stateOrProvinceName' => 'State', 'localityName' => 'SomewhereCity', 'organizationName' =>'MySelf', 'organizationalUnitName' => 'Whatever', 'commonName' => 'mySelf', 'emailAddress' => '[email protected]');
//Passphrase can be taken during registration
//Here its initialized to 1234 for sample
$privkeypass = 'root';
$numberofdays = 365;
//RSA encryption and 1024 bits length
$privkey = openssl_pkey_new(array('private_key_bits' => 1024,'private_key_type' => OPENSSL_KEYTYPE_RSA));
$csr = openssl_csr_new($dn, $privkey);
$sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays);
openssl_x509_export($sscert, $publickey);
openssl_pkey_export($privkey, $privatekey, $privkeypass);
openssl_csr_export($csr, $csrStr);
//Generated keys are stored into files
$fp=fopen('../PKI/private/$userid.key','w');
fwrite($fp,$privatekey);
fclose($fp);
$fp=fopen('../PKI/public/$userid.crt','w');
fwrite($fp,$publickey);
fclose($fp);
}
//Encryption with public key
function encrypt($source,$rc)
{
//path holds the certificate path present in the system
$path='../PKI/public/server.crt';
$fp=fopen($path,'r');
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
//$source=';
//$source='sumanth ahoiadodakjaksdsa;ldadkkllksdalkalsdl;asld;ls sumanthasddddddddddddddddddddddddddddddddfsdfsffdfsdfsumanth';
$j=0;
$x=strlen($source)/10;
$y=floor($x);
for($i=0;$i<$y;$i++)
{
$crypttext=';
openssl_public_encrypt(substr($source,$j,10),$crypttext,$pub_key);$j=$j+10;
$crt.=$crypttext;
$crt.=':::';
}
if((strlen($source)%10)>0)
{
openssl_public_encrypt(substr($source,$j),$crypttext,$pub_key);
$crt.=$crypttext;
}
return($crt);
}
//Decryption with private key
function decrypt($crypttext,$userid)
{
$passphrase='root';
$path='../PKI/private/server.key';
$fpp1=fopen($path,'r');
$priv_key=fread($fpp1,8192);
fclose($fpp1);
$res1= openssl_get_privatekey($priv_key,$passphrase);
$tt=explode(':::',$crypttext);
$cnt=count($tt);
$i=0;
while($i<$cnt)
{
openssl_private_decrypt($tt[$i],$str1,$res1);
$str.=$str1;
$i++;
}
return $str;
}
function sign($source,$rc)
{
$has=sha1($source);
$source.='::';
$source.=$has;
$path='../PKI/public/$rc.crt';
$fp=fopen($path,'r');
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
openssl_public_encrypt($source,$mese,$pub_key);
return $mese;
}
function verify($crypttext,$userid)
{
$passphrase='root';
$path='../PKI/private/$userid.key';
$fpp1=fopen($path,'r');
$priv_key=fread($fpp1,8192);
fclose($fpp1);
$res1= openssl_get_privatekey($priv_key,$passphrase);
openssl_private_decrypt($crypttext,$has1,$res1);
list($c1,$c2)=split('::',$has1);
$has=sha1($c1);
if($has$c2)
{
$message=$c1;
return $message;
}
}
}
?>