Encrypt in PHP openssl and decrypt in javascript CryptoJS
JavaScript
function CryptoJSAesDecrypt(passphrase,encrypted_json_string){
var obj_json = JSON.parse(encrypted_json_string);
var encrypted = obj_json.ciphertext;
var salt = CryptoJS.enc.Hex.parse(obj_json.salt);
var iv = CryptoJS.enc.Hex.parse(obj_json.iv);
var key = CryptoJS.PBKDF2(passphrase, salt, { hasher: CryptoJS.algo.SHA512, keySize: 64/8, iterations: 999});
var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv});
return decrypted.toString(CryptoJS.enc.Utf8);
}
console.log(CryptoJSAesDecrypt('your passphrase','<?php echo $string_json_fromPHP?>'));function CryptoJSAesEncrypt($passphrase, $plain_text){
$salt = openssl_random_pseudo_bytes(256);
$iv = openssl_random_pseudo_bytes(16);
//on PHP7 can use random_bytes() istead openssl_random_pseudo_bytes()
//or PHP5x see : https://github.com/paragonie/random_compat
$iterations = 999;
$key = hash_pbkdf2("sha512", $passphrase, $salt, $iterations, 64);
$encrypted_data = openssl_encrypt($plain_text, 'aes-256-cbc', hex2bin($key), OPENSSL_RAW_DATA, $iv);
$data = array("ciphertext" => base64_encode($encrypted_data), "iv" => bin2hex($iv), "salt" => bin2hex($salt));
return json_encode($data);
}
$string_json_fromPHP = CryptoJSAesEncrypt("your passphrase", "your plain text");
Also in JavaScript:
- Title
- git empty commit
- Category
- JavaScript
- Title
- function takes object name and property name and new value
- Category
- JavaScript
- Title
- how to make a show password button
- Category
- JavaScript
- Title
- add a route to a buttoin in angular
- Category
- JavaScript
- Title
- how to use jQuery hide and show to display multiple images
- Category
- JavaScript
- Title
- dockerfile for nodejs
- Category
- JavaScript
- Title
- how to create duplicate key array in javascript
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- how to remove first character from string in javascript
- Category
- JavaScript
- Title
- how to get element by title js
- Category
- JavaScript
- Title
- icon shwoing a box react native vector icons
- Category
- JavaScript
- Title
- discord.js tagging the author
- Category
- JavaScript
- Title
- how to make a textarea unwritable in react native
- Category
- JavaScript
- Title
- firebase configuration on functions
- Category
- JavaScript
- Title
- addEnd Point js
- Category
- JavaScript
- Title
- Data Change with Mutation
- Category
- JavaScript
- Title
- how to include local image files in javascript object
- Category
- JavaScript
- Title
- document ready
- Category
- JavaScript
- Title
- javascript array pop
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- dynamic for loop react
- Category
- JavaScript
- Title
- javascript add function to onchange event
- Category
- JavaScript
- Title
- ${ js
- Category
- JavaScript
- Title
- html get class property
- Category
- JavaScript
- Title
- html get elements by class
- Category
- JavaScript
- Title
- how to find unique elements in array in javascript
- Category
- JavaScript
- Title
- discord.js ticket system stackoverflow
- Category
- JavaScript
- Title
- how to count click events javascript
- Category
- JavaScript
- Title
- how to iterate through an object in javascript
- Category
- JavaScript
- Title
- express how to access ajax post data
- Category
- JavaScript
- Title
- generate bearer token
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- get value of hidden field jquery
- Category
- JavaScript
- Title
- angular list contains property
- Category
- JavaScript
- Title
- angular attach component to body
- Category
- JavaScript
- Title
- delete last element of array js
- Category
- JavaScript
- Title
- how to get the index of an array in javascript
- Category
- JavaScript
- Title
- Add object to array javascript
- Category
- JavaScript
- Title
- assign values to a table from javascript in VF page
- Category
- JavaScript
- Title
- event listener on parent not on childjavascript
- Category
- JavaScript
- Title
- how to remove duplicate array object in javascript
- Category
- JavaScript
- Title
- .shift js
- Category
- JavaScript
- Title
- get day js
- Category
- JavaScript
- Title
- how to get today date in javascript
- Category
- JavaScript
- Title
- insert into specific array index that has a value existing on that index
- Category
- JavaScript
- Title
- async await arrow function
- Category
- JavaScript
- Title
- An unhandled exception occurred: Script file ../node_modules/jquery/dist/jquery.min.js does not exist.
- Category
- JavaScript
- Title
- add custom marker in react-mapbox-gl
- Category
- JavaScript
- Title
- graphql react filtering
- Category
- JavaScript
- Title
- find substring in string javascript
- Category
- JavaScript
- Title
- how the map function works javascript
- Category
- JavaScript
- Title
- change innertext javascript
- Category
- JavaScript
- Title
- array sort by key javascript
- Category
- JavaScript
- Title
- edit onclick event
- Category
- JavaScript
- Title
- electron new window
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- firefox extension make ajax request
- Category
- JavaScript
- Title
- how to get a user input in js
- Category
- JavaScript
- Title
- how to add multiple videos in html5 with javascript
- Category
- JavaScript
- Title
- how to render different pages in nodes
- Category
- JavaScript
- Title
- get attribute value jquery
- Category
- JavaScript
- Title
- google maps api javascript
- Category
- JavaScript
- Title
- clear the console while in strict mode
- Category
- JavaScript
- Title
- empty array js
- Category
- JavaScript
- Title
- comparing arrays javascript
- Category
- JavaScript
- Title
- angularjs socket.io
- Category
- JavaScript
- Title
- express bodyparser deprecated
- Category
- JavaScript
- Title
- Add table row in jQuery
- Category
- JavaScript
- Title
- how to take input in javascript in coding
- Category
- JavaScript
- Title
- how to make a text editor in html
- Category
- JavaScript
- Title
- add readonly attribute jquery
- Category
- JavaScript
- Title
- ionic modal navbar not showing
- Category
- JavaScript
- Title
- iterate through array javascript
- Category
- JavaScript
- Title
- check if var is array js
- Category
- JavaScript
- Title
- boucle for in js
- Category
- JavaScript
- Title
- caesar cipher javascript code
- Category
- JavaScript
- Title
- how to import jquery in js file
- Category
- JavaScript
- Title
- creating an object javascript
- Category
- JavaScript
- Title
- firebase cheat sheet
- Category
- JavaScript
- Title
- adding pre tag javascript
- Category
- JavaScript
- Title
- angular bootstrap not working
- Category
- JavaScript
- Title
- how to deep copy object in javascript
- Category
- JavaScript
- Title
- generate random numbers in js
- Category
- JavaScript
- Title
- enzyme check state
- Category
- JavaScript
- Title
- how to download express without view
- Category
- JavaScript
- Title
- display none js
- Category
- JavaScript
- Title
- how to add object to array javascript
- Category
- JavaScript
- Title
- for javascript delay
- Category
- JavaScript
- Title
- how to make text come up with javascript
- Category
- JavaScript
- Title
- how to see if a web site is useing react
- Category
- JavaScript
- Title
- Hoisting in JavaScript MDN
- Category
- JavaScript
- Title
- how to remove item from array javascript
- Category
- JavaScript
- Title
- bind and unbind jquery validation
- Category
- JavaScript
- Title
- how to find out what a string ends with in javascript
- Category
- JavaScript
- Title
- how to create a variable in javascript
- Category
- JavaScript
- Title
- Code is valid JSON equivalent of the key/value pair shown that also preserves the original value: UPC: 043875
- Category
- JavaScript
- Title
- bind in javascript
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- Cannot set property 'innerHTML' of null
- Category
- JavaScript