In this article, I will share with you how to encrypted and decrypted data using openssl_encrypt function with example. as you know data security is very important part in web application when you working on the large application. in laravel you can done it very simple way. you can encrypt and decrypt your data by using openssl_encrypt() function. here i share with simple example forr how to make your data very secure and not anyone encrypted without your hash key.
$encrypt_method = "AES-256-CBC";
$secret_key = '7aE3OKIZxusugQdpk3gwNi9x63MRAFLgkMJ4nyil88ZYMyjqTSE3FIo8L5KJghfi';
$secret_iv = '7aE3OKIZxusugQdpk3gwNi9x63MRAFLgkMJ4nyil88ZYMyjqTSE3FIo8L5KJghfi';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
$string = $input['card_no'].'-'.$input['ccExpiryMonth'].'-'.$input['ccExpiryYear'].'-'.$input['cvvNumber'];
// encrypt token;
$encryptToken = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$encryptToken = base64_encode($encryptToken);
// decrypt token
$decryptToken = openssl_decrypt(base64_decode($encryptToken), $encrypt_method, $key, 0, $iv);
// output
dd($decryptToken);
$frameware = $tokens;
$encrypt_method = "AES-256-CBC";
$secret_key = '7aE3OKIZxusugQdpk3gwNi9x63MRAFLgkMJ4nyil88ZYMyjqTSE3FIo8L5KJghfi';
$secret_iv = '7aE3OKIZxusugQdpk3gwNi9x63MRAFLgkMJ4nyil88ZYMyjqTSE3FIo8L5KJghfi';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
// decrypt token
$decryptToken = openssl_decrypt(base64_decode($frameware), $encrypt_method, $key, 0, $iv);
// convert in array
$decryptTokenArray = json_decode($decryptToken, 1);
// output
dd($decryptTokenArray);
it will help you lot.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Angular 12 Crop Image Preview Before Upload using ngx-image-cropper
In this article, we will discuss the ang...Form Validation in VueJs using Vuelidate
This is a comprehensive Vue.js 2+ Form t...How to get Local Time Instead of Server Time
Suppose you are managing blog website an...How to Split a String into an Array of Characters in JavaScript
Use the split() Method The JavaScript...Laravel 5.5 - simple crud operation with example
Today, we are sharing how to make s...