Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 4debd44

Browse files
committed
updated version
added warning for non supported chars in passphrase updated tests
1 parent 9f49de2 commit 4debd44

7 files changed

Lines changed: 30 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# CryptoJS 3.x AES encryption/decryption on client side with Javascript and on server side with PHP
1+
# CryptoJS 3.x AES encryption/decryption on client side with Javascript and on server side with PHP
2+
3+
[![Tests](https://github.com/brainfoolong/cryptojs-aes-php/actions/workflows/tests.yml/badge.svg)](https://github.com/brainfoolong/cryptojs-aes-php/actions/workflows/tests.yml)
4+
25

36
A tool to AES encrypt/decrypt data in javascript and/or PHP. You can use it for PHP only, for Javascript only or mix it together.
47

@@ -76,6 +79,9 @@ Also, there's a good article about PHP issues/info related to this library: http
7679
* Does not work with following php.ini option enabled: http://php.net/manual/en/mbstring.overload.php
7780

7881
## Changelog
82+
* 2.2.0 - 13\. June 2023
83+
* added tests for php and js
84+
* show a warning for passphrases with non ASCII characters, as it is and was never supported
7985
* 2.1.1 - 15\. January 2021
8086
* just a few documentation and composer fixes
8187
* 2.1.0 - 30\. December 2020

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@
2222
"Nullix\\CryptoJsAes\\": "src/"
2323
}
2424
},
25-
"version": "2.1.1",
25+
"archive": {
26+
"exclude": [
27+
"/tests",
28+
".gitignore",
29+
"package.json",
30+
"playwright.config.ts"
31+
]
32+
},
33+
"version": "2.2.0",
2634
"require": {
2735
"php": ">=7.0.0",
2836
"ext-openssl": "*",

dist/cryptojs-aes-format.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* AES JSON formatter for CryptoJS
33
* @link https://github.com/brainfoolong/cryptojs-aes-php
4-
* @version 2.1.1
4+
* @version 2.2.0
55
*/
66

77
var CryptoJSAesJson = {
@@ -12,6 +12,9 @@ var CryptoJSAesJson = {
1212
* @return {string}
1313
*/
1414
'encrypt': function (value, password) {
15+
if (password.match(/[^\x00-\x7F]/)) {
16+
console.warn('CryptoJSAES: Your passphrase contains non ASCII characters - This is not supported. Hash your passphrase with MD5 or similar hashes to prevent those issues')
17+
}
1518
return CryptoJS.AES.encrypt(JSON.stringify(value), password, { format: CryptoJSAesJson }).toString()
1619
},
1720
/**
@@ -21,6 +24,9 @@ var CryptoJSAesJson = {
2124
* @return {*}
2225
*/
2326
'decrypt': function (jsonStr, password) {
27+
if (password.match(/[^\x00-\x7F]/)) {
28+
console.warn('CryptoJSAES: Your passphrase contains non ASCII characters - This is not supported. Hash your passphrase with MD5 or similar hashes to prevent those issues')
29+
}
2430
return JSON.parse(CryptoJS.AES.decrypt(jsonStr, password, { format: CryptoJSAesJson }).toString(CryptoJS.enc.Utf8))
2531
},
2632
/**

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"devDependencies": {
3-
"typescript": "^4.7.4",
4-
"@playwright/test": "^1.24.1"
3+
"typescript": "^4.9.5"
4+
},
5+
"dependencies": {
6+
"@playwright/test": "^1.35.0"
57
}
68
}

src/CryptoJsAes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* PHP 7.x and later supported
1414
* If you need PHP 5.x support, goto the legacy branch https://github.com/brainfoolong/cryptojs-aes-php/tree/legacy
1515
* @link https://github.com/brainfoolong/cryptojs-aes-php
16-
* @version 2.1.1
16+
* @version 2.2.0
1717
*/
1818
class CryptoJsAes
1919
{

tests/test-js.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
break
2828
case 'encode': {
2929
const encrypted = CryptoJSAesJson.encrypt(originalValue, password)
30-
console.log(encrypted)
3130
if (encrypted.includes('"ct"') && encrypted.includes('"iv"') && encrypted.includes('"s"')) {
3231
results.innerText = 'OK'
3332
}

tests/test.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ test('Run all tests', async ({ page }) => {
77
})
88
const phpPortMapping = [
99
9970, // 7.0
10-
//9982, // 8.2
10+
9982, // 8.2
11+
9999, // latest
1112
]
1213
const actionsMap = ['encode', 'decode', 'cross']
1314
for (let i = 0; i < phpPortMapping.length; i++) {

0 commit comments

Comments
 (0)