brainfoolong / cryptojs-aes-php Goto Github PK
View Code? Open in Web Editor NEWCryptoJS AES encryption/decryption on client side with Javascript and on server side with PHP
License: MIT License
CryptoJS AES encryption/decryption on client side with Javascript and on server side with PHP
License: MIT License
Hello,
first of all, thanks for that great work, its very hard to find an easily and JS encrypt and PHP decrypt library.
But I have an issue. I would like to use the id of the json input, but due the encryption is handled by jQuery, I dont get it to work.
Instead of sending a form, I want to get it handled by a XHR request and displaying the result without loading another page.
But I dont know what to change in the jquery code to make it work instead with xhr, due I dont get it to use the id of the input field, but always need the name.
Hope you can help and change the jquery code to pure js.
Thanks
Ps. Some code explaining would be fine too ;)
Hello,
CERT PL found a security vulnerability in this repository. How can we report this privately? We don't see any security policy describing how such vulnerabilities should be reported.
Hi, thanks for this repo. it's great. I found another package that when I use it, it takes 19 seconds to be decrypt a long text, and yours do it in 17 seconds, and because of this 2 secondes I wanna use yours.
1- But my question is that can you incresase it's speed? it's too slow yet.
2-this decrypting takes 17 seconds in chrome but 9 seconcs in firefox, why this happens?
3- what is that "iv":"XXX","s":"XXX" at the last of code? (it's because of {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8) )
4- what is the blocksize in your AES code? 128,192 or 256? and we can't select blocksize! Is it safe enough? (I use a secure password)
5- when I deccypt a gzcompressed text by your code, why there is no difference in time between compressed text and plain text? previous package that I used decypts the compressed text in 17 seconds and the plain text in 24 seconds!
# -*- coding: utf-8 -*-
import binascii
import base64
import hashlib
import json
from Crypto import Random
from Crypto.Cipher import AES
class AESCipher(object):
bs = 16
@staticmethod
def md5(s, raw_output=False):
"""Calculates the md5 hash of a given string"""
if isinstance(s, str):
s = s.encode()
res = hashlib.md5(s)
if raw_output:
return res.digest()
return res.hexdigest()
def encrypt(self, data, key, salt=None):
"""
:param data: str
:param key: str
:param salt: str
:return:
"""
if not salt:
salt = Random.new().read(8)
else:
salt = binascii.unhexlify(salt)
salted = b''
dx = b''
while len(salted) < 48:
dx = self.md5(dx + key.encode('utf-8') + salt, True)
salted += dx
key = salted[:32]
iv = salted[-16:]
raw = self._pad(json.dumps(data).replace(' ', ''))
cipher = AES.new(key, AES.MODE_CBC, iv)
enc = cipher.encrypt(raw.encode('utf-8'))
return base64.b64encode(enc), binascii.hexlify(iv), binascii.hexlify(salt)
def decrypt(self, enc, iv, key, salt):
"""
:param enc: str
:param iv: str
:param key: str
:param salt: str
:return:
"""
concated_passphrase = key.encode() + binascii.unhexlify(salt)
md5_salt = self.md5(concated_passphrase, True)
md5_list = [md5_salt]
result = md5_list[0]
for i in [1, 2]:
md5_list.append(self.md5(md5_list[i - 1] + concated_passphrase, True))
result += md5_list[i]
key = result[:32]
enc = base64.b64decode(enc)
iv = binascii.unhexlify(iv)
cipher = AES.new(key, AES.MODE_CBC, iv)
return self._unpad(cipher.decrypt(enc)).decode('utf-8')
def _pad(self, s):
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
@staticmethod
def _unpad(s):
return s[:-ord(s[len(s) - 1:])]
写得略微粗糙,亲测能用,需要自取
Edited... Malicious content...
Hi, I was so excited when I found your work, because I've been looking all over for a solution to be able to use crypto.js output with php. However, I seem to be having the same problem with your implementation that I was having before... the php side returns a NULL value.
I went ahead and put your example up as a test at http://gateway.southgateaz.org:8004/aes_test.php. I'm not sure what I'm missing. I'm just wondering if you've run into this or if you have any pointers. Thanks!
-Gus
hi, i'm doing the same for example but i can't get any data at all. I use Ajax, so I am having a problem. I am sharing the sample code.
JS
`
var htmlVal = $(".summernote").val()
var cryptoVal = CryptoJS.AES.encrypt(JSON.stringify(htmlVal), "mysecret", {format: CryptoJSAesJson}).toString();
$.ajax({
type: 'POST',
url: base_url + '/mail/preview',
data: "json=" + cryptoVal,
dataType: 'json',
success: function(e) {
console.log(e);
},
});
`
PHP
echo $this->cryptoJsAesDecrypt("mysecret", $_POST["json"]);
I am debugging the cryptoJsAesDecrypt method. $ ct value comes smoothly. But it doesn't give back data in openssl section. Openssl active on my server
I am pretty much copying your example - in php
$encrypted_mm = Helper::cryptoJsAesEncrypt('foobar', '123456');
echo $encrypted_mm ;
//which gives me this //{"ct":"pi6z3m0q4jscZKuhXobHoQ==","iv":"6311ee9d122636ac3bf9a0a9abc4b370","s":"f0f067ba05bdb331"}
then in js
let encrypted = '{"ct":"pi6z3m0q4jscZKuhXobHoQ==","iv":"6311ee9d122636ac3bf9a0a9abc4b370","s":"f0f067ba05bdb331"}'
let password = '123456'
let decrypted = CryptoJS.AES.decrypt(encrypted, password, { format: CryptoJSAesJson }).toString(CryptoJS.enc.Utf8)
console.log('Decrypted: ' + decrypted)
// it is empty..but when I use your foobar encrypted values it works...any idea...fighting for 3 straight hours..
Hello Roland (@brainfoolong brainfoolong).
I am a junior developer, I have the task of implementing password verification on Laravel, on a project migrating from Node.
In the old platform, they used CryptoJs like this:
password: cryptojs.encrypt(JSON.stringify(req.body.password), secretKey).toString();
-----
let bytes = AES.decrypt(user.password.toString(), aesKey);
result = password === JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
In Laravel tried this
$newEncrypter = new \Illuminate\Encryption\Encrypter(config('app.secret_key'), config('app.cipher'));
$decrypted = $newEncrypter->decrypt( $encrypted );
tinker output: Illuminate\Contracts\Encryption\DecryptException The payload is invalid.
Also tried this and it return false
public function check($value, $hashedValue, array $options = [])
{
$hashedBytes = base64_decode($hashedValue);
$iv = substr($hashedBytes, 0, openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = substr($hashedBytes, openssl_cipher_iv_length('aes-256-cbc'));
$decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', $this->key, OPENSSL_RAW_DATA, $iv);
return $value === $decrypted;
}
Then I found your solution, tried to implement it but it didn't work.
You use salt, vector.
I don't have that.
And judging by the code, past developers did not use it.
I have an encrypted strings (in DB).
One original password and encrypted string (for tests)
And the key (aesKey).
I've been trying to come up with something for the second day, or find something on Google or Stackoverflow, but I can't.
Maybe you will have some ideas
Can use toString(CryptoJS.enc.Utf8)) ? Just going to ecrypt and decrypt w text with arabic france letters i wanna make sure if that function exist
I would like to encrypt using PHP and decrypt in JS without the reliance on JSON. Just a plane old AES string. Is that possible?
Thanks for your code... it's most appreciate. I have a question... is it possible to have in output a simpler encryption string?
This is the code that I following:
<?php
$valTxt="MyText";
$pswd="MyPassword";
echo "<p>Text to Crypt: ".$valTxt." </p>";
echo "<p>Password: ".$pswd." </p>";
$encrypted = cryptoJsAesEncrypt($pswd, $valTxt);
echo "<p> Encrypted PHP: ".$encrypted." </p>";
$decrypted = cryptoJsAesDecrypt($pswd, $encrypted);
echo "<p> Decrypted PHP: ".$decrypted." </p>";
?>
<script>
var valEnc='<?php echo $encrypted;?>';
var pswdDec='<?php echo $pswd;?>';
</script>
<p>Testo Decriptato JS: -------- <span id="result"></span></p><br><br>
<script>
var decrypted = JSON.parse(CryptoJS.AES.decrypt(valEnc, pswdDec, {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8));
document.getElementById("result").innerHTML = decrypted;
</script>
As you can see in output I have a string like this:
{"ct":"UbDpkBRT1R5Tbt+hp0nX6w==","iv":"6c113edfbc0d7d917294ecdfc4d61d6f","s":"a872cd319b0d2a52"}
I would like to have an encrypted string more simple because I would like that an user can write it.
I thought that the user digits "ct" (better if the string is 16 char between A-Za-z0-9) and I pass to the function "iv" and "s".
An example from your is most appreciate because I'm a beginner... thanks
Where can I get the unminified version of cryptojs-aes.min.js ?
Please could you change the license to Apache 2.0 or MIT?
Otherwise the scope where the functions can get used (without violating the license) is quite limited.
Hi developer,
Thanks for providing the PHP lib for CryptoJS.
Here I found a problem when ct encoded with CryptoJS containing with any space and then it got failed to be decode with php.
How could I do to solve this issue?
Thanks!
how can I consider my own IV within this project? both PHP and in cryptojs
Hi, sorry for putting this issue in this page because the project I had issue with had been archived. I really appreciate the project "web-ftp-client" you've done. I was wondering that is there any way I can install the ftp-client in linux server and download the file to local machine?
Thanks
the decrypt function returns empty when the value is generated from javascript
php:
public static function decrypt($jsonStr)
{
$json = json_decode($jsonStr, true);
$salt = hex2bin($json["s"]);
$iv = hex2bin($json["iv"]);
$ct = base64_decode($json["ct"]);
$concatedPassphrase = env('CRYPTO_KEY') . $salt;
$md5 = [];
$md5[0] = md5($concatedPassphrase, true);
$result = $md5[0];
for ($i = 1; $i < 3; $i++) {
$md5[$i] = md5($md5[$i - 1] . $concatedPassphrase, true);
$result .= $md5[$i];
}
$key = substr($result, 0, 32);
$data = openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
return json_decode($data, true);
}
javascript:
var CryptoJSAesJson = {
stringify: function (cipherParams) {
var j = { ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64), iv:'', s:'' }
if (cipherParams.iv) j.iv = cipherParams.iv.toString()
if (cipherParams.salt) j.s = cipherParams.salt.toString()
return (JSON.stringify(j))
},
parse: function (jsonStr) {
var j = JSON.parse((jsonStr))
var cipherParams = CryptoJS.lib.CipherParams.create({ ciphertext: CryptoJS.enc.Base64.parse(j.ct) })
if (j.iv) cipherParams.iv = CryptoJS.enc.Hex.parse(j.iv)
if (j.s) cipherParams.salt = CryptoJS.enc.Hex.parse(j.s)
return cipherParams
}
}
var encrypted = CryptoJS.AES.encrypt(JSON.stringify('123456'), environment.keyCrypt, { format: CryptoJSAesJson }).toString()
test
Please share your details so we can contact you for one of project.
Regards,
Ashish
i want use cryptojs-aes.php with https://github.com/brix/crypto-js but it not work , can you help ?
Hello, there we are using crypto js to encrypt username and password in login. The code is as follows.
var username = $("#username").val();
var password1 = $("#password").val();
var password = "123456";
username = CryptoJSAesJson.encrypt(username, password);
password1 = CryptoJSAesJson.encrypt(password1, password);
$("#username").val(username);
$("#password").val(password1);
form.submit();
$('#login_form')[0].reset();
but here reset is not working on the Mac device. Can you please check and let me help.
Thanks In advance!
The code below works on the client. How can I decode it using PHP?
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
<script type="text/javascript">
var bytes = CryptoJS.AES.decrypt("U2FsdGVkX1/q1v3+WzARwxPwzV6PQ6cUzk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nygemm/n1ywSKNuYU1SmNcu+1lg1d4aoMbUZ/fSA3VdIvo7aepWx4ER+5Q12xsu9iKDxIRXJeMxQaKjrA37YtodSZ2opect4+eyA5Ksun7SZ3/o7/NNEc925760Ik3hGDxxdwPjQAdkXIeu//a6Idl+cjW9bqzqLiqPV+C32gP3LbXe0kQVLhNnM+LSxYGIIkcLB55vI5lhdj8LFY6ucB8N8XqY2XNJ5gDVs0niiWUWwkEq6Gs2vXZN/8ZF9BWHXuwB6GKPPsO8PtRUJT24uGBhhYaymhhBwziBd8E8boHXu7DvCXUtBivVsFwYamq7+0yEyvxa1fvBFNw2tX4GQ9y0IuG9pDyIWpwhr+wW4ucuQrQXBH/Z6iG27rjrvDn3z70JMtv+uX4Vj9rvZ1qDT9ClzzW+CkuTZDBIFZpYamQIlzRDzC/2jDrMOb8lMhBv2WzHfKLUg0yzOMQgP0yforo6NmUzuKcIFKOonWvbNsx14LobhZ4JSzrlVrPj6Hue4/9W/nw1zdxdW4HaRcnTJMOJrUe1m2vFbaMnF8mh2fzSY5YDSRpUSbaxQ2XdSfmPd/UTAXd7j2kJhMcIQGD5ldWG3OYucWT4vfqSUOqTjBAMrRjKrhxg8/YGEmduEKhNsB71dRM9lLudkvysPVWiM1qGxGbXaNulJf58h75CBugo8OKi6xzRJgTzh58WmDjpKEF40v6wTvqG7qHM5jEyZo3qO3TQThemErPJaWhgpiVNOeDpRxGW4zJb/uwm8rUV8LTEZfgCeMX/AWmqygu1gj4L4uO95xEJQ2h+x","U2FsdGVkX1/FhXfmnDLMdW/zwst2X9dIxPuBfc876cs=");
document.write(bytes.toString(CryptoJS.enc.Utf8));
</script>
Hey, sorry to bother you.
I'm implementing you lib in a already exists cordova project project:
JS:
`let password = 'TestEncrypt'
var data = new Object();
data.mail = CryptoJS.AES.encrypt($(".mailLogin").val(), password, { format: CryptoJSAesJson }).toString();
cordova.plugin.http.get('https://...', {}, { data: JSON.stringify(data) }, function(response) {
jsonobj = JSON.parse(response.data);
M.toast({ html: jsonobj.most_used_message }, 4000) // 4000 is the duration of the toast
if (jsonobj.message_code == "200") {
}
}, function(response) {
console.error(response);
});`
It's working fine here and I'm receiving It on the severside.
But here it's going wrong here! decrypt function returns a empty value.
PHP:
$passwordEN = "TestEncrypt"; CryptoJsAes::decrypt($data["mail"],$passwordEN)
MORE:
Thanks for you time
Hi.
I tried to run this library on PHP 5.3 and it didn't failed, but it didn't worked well neither.
What is the minimum version that this library/function requires ?
Thanks.
I encrypt in JS and decrypt in PHP decrypt value return empty
I encrypted an array in php and want to decrypt the response data with js.
cryptoJsAesEncrypt('pass', some_data); = ok
JSON.parse(CryptoJS.AES.decrypt(some_encrypted_data, "pass", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8)) = failed
TypeError: Cannot read property 'length' of undefined
at Object.u.enc.Base64.parse (aes.js:14)
at Object.CryptoJSAesJson.parse (app.js:558)
at Object.d.SerializableCipher.l.extend._parse (aes.js:30)
at Object.d.PasswordBasedCipher.a.extend.decrypt (aes.js:31)
at Object.decrypt (aes.js:25)
Any ideas?
Ok im pretty new to php/javascript so im just wondering how I use the encrypting in javascript since it is not a function, it is just a variable.
it's not working js encrypts but the php side it's not doing anyhing
I am getting JSON error while i pass data from php file.
HTML
<script src="cryptojs-aes-php-master/example/aes.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script src="cryptojs-aes-php-master/aes-json-format.js"></script>
PHP File
$encodeanswer[]=htmlentities(cryptoJsAesEncrypt($answer,"123"))
JS File
console.log(value);
//{"ct":"9i4gxztr7W7W0sPFKo1SKA==","iv":"5fba99d002577c64ce4421a979d49f40","s":"fe836ae24c8ca962"}
var parsedvalue = value.replace(/"/g,'"')
console.log(parsedvalue);
//{ ct: "nPR3gyDA5Q6Qra1Py9GtAA==", iv: "7e10905af0f4d0ba3fb2cfeb5d77ae8e", s: "ee20cfb01b5b25b6" }
console.log(JSON.parse(CryptoJS.AES.decrypt(parsedvalue,"123", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8)));
//SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Note: I tested your example and it populating data in input box.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.