{"id":13405190,"url":"https://github.com/brainfoolong/cryptojs-aes-php","last_synced_at":"2026-01-10T19:04:38.863Z","repository":{"id":24856819,"uuid":"28272108","full_name":"brainfoolong/cryptojs-aes-php","owner":"brainfoolong","description":"CryptoJS AES encryption/decryption on client side with Javascript and on server side with PHP","archived":true,"fork":false,"pushed_at":"2024-08-15T19:44:19.000Z","size":128,"stargazers_count":399,"open_issues_count":0,"forks_count":158,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-09-15T22:38:20.430Z","etag":null,"topics":["aes-encryption","cryptojs","javascript","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainfoolong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"brainfoolong","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2014-12-20T16:25:56.000Z","updated_at":"2024-08-19T09:20:09.000Z","dependencies_parsed_at":"2023-11-30T06:30:45.774Z","dependency_job_id":"a11aa7de-3f78-4b52-af0a-9f99c2e991ae","html_url":"https://github.com/brainfoolong/cryptojs-aes-php","commit_stats":{"total_commits":40,"total_committers":4,"mean_commits":10.0,"dds":0.475,"last_synced_commit":"c9dae73c8944a84cfb47e9506835bbd7d20af196"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fcryptojs-aes-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fcryptojs-aes-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fcryptojs-aes-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fcryptojs-aes-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainfoolong","download_url":"https://codeload.github.com/brainfoolong/cryptojs-aes-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221454075,"owners_count":16824598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes-encryption","cryptojs","javascript","php"],"created_at":"2024-07-30T19:01:57.121Z","updated_at":"2025-03-14T09:32:33.664Z","avatar_url":"https://github.com/brainfoolong.png","language":"PHP","funding_links":["https://github.com/sponsors/brainfoolong"],"categories":["PHP"],"sub_categories":[],"readme":"# CryptoJS AES encryption/decryption on client side with Javascript and on server side with PHP\n\n[![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)\n\n\u003e [!IMPORTANT] \n\u003e This library is considered deprecated, read-only and superseeded by my newer library https://github.com/brainfoolong/js-aes-php - It's basically the same without the need for the third party library `CryptoJS`.\n\nA tool to AES encrypt/decrypt data in javascript and/or PHP. You can use it for PHP only, for Javascript only or mix it\ntogether.\n\nIt uses default `aes-256-cbc` implementation with random salts and random initialization vector. This library does not\nsupport other ciphers or modes.\n\n## Features\n\n* Encrypt any value in Javascript (objects/array/etc...) - Everything that can be passed to `JSON.stringify`\n* Encrypt any value in PHP  (object/array/etc...) - Everything that can be passed to `json_encode`\n* Decrypt in PHP/Javascript, doesn't matter where you have encrypted the values\n\n## How to use\n\n###### PHP | See [dist/example-php.php](https://github.com/brainfoolong/cryptojs-aes-php/blob/master/dist/example-php.php)\n\nYou need the file `src/CryptoJsAes.php`\n\n```php\n\u003c?php\nuse Nullix\\CryptoJsAes\\CryptoJsAes;\nrequire \"CryptoJsAes.php\";\n\n// encrypt\n$originalValue = [\"We do encrypt an array\", \"123\", ['nested']]; // this could be any value\n$password = \"123456\";\n$encrypted = CryptoJsAes::encrypt($originalValue, $password);\n// something like: {\"ct\":\"g9uYq0DJypTfiyQAspfUCkf+\\/tpoW4DrZrpw0Tngrv10r+\\/yeJMeseBwDtJ5gTnx\",\"iv\":\"c8fdc314b9d9acad7bea9a865671ea51\",\"s\":\"7e61a4cd341279af\"}\n\n// decrypt\n$encrypted = '{\"ct\":\"g9uYq0DJypTfiyQAspfUCkf+\\/tpoW4DrZrpw0Tngrv10r+\\/yeJMeseBwDtJ5gTnx\",\"iv\":\"c8fdc314b9d9acad7bea9a865671ea51\",\"s\":\"7e61a4cd341279af\"}';\n$password = \"123456\";\n$decrypted = CryptoJsAes::decrypt($encrypted, $password);\n\necho \"Encrypted: \" . $encrypted . \"\\n\";\necho \"Decrypted: \" . print_r($decrypted, true) . \"\\n\";\n```\n\n###### Javascript | See [dist/example-js.html](https://github.com/brainfoolong/cryptojs-aes-php/blob/master/dist/example-js.html)\n\nYou need the file `dist/cryptojs-aes.min.js` and `dist/cryptojs-aes-format.js`\n\n```html\n\n\u003cscript src=\"dist/cryptojs-aes.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"dist/cryptojs-aes-format.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    (function () {\n        // encrypt value\n        let valueToEncrypt = 'foobar' // this could also be object/array/whatever\n        let password = '123456'\n        let encrypted = CryptoJSAesJson.encrypt(valueToEncrypt, password)\n        console.log('Encrypted:', encrypted)\n        // something like: {\"ct\":\"10MOxNzbZ7vqR3YEoOhKMg==\",\"iv\":\"9700d78e12910b5cccd07304333102b7\",\"s\":\"c6b0b7a3dc072248\"}\n    })()\n\u003c/script\u003e\n\u003cscript\u003e\n    (function () {\n        // decrypt value\n        let encrypted = '{\"ct\":\"hQDvpbAKTGp1mXgzSShR9g==\",\"iv\":\"57fd85773d898d1f9f868c53b436e28f\",\"s\":\"a2dac436512077c5\"}'\n        let password = '123456'\n        let decrypted = CryptoJSAesJson.decrypt(encrypted, password)\n        console.log('Decrypted:', decrypted)\n    })()\n\u003c/script\u003e\n```\n\n## Composer Install\n\n    composer require brainfoolong/cryptojs-aes-php\n\n## Supported PHP versions\n\n* 8.x\n* 7.x\n* 5.x (head to the [legacy branch](https://github.com/brainfoolong/cryptojs-aes-php/tree/legacy))\n\n## Security Notes\n\nSince the time that this library has been created, encryption technologies has been evolved. This library and using\nAES-256-CBC encryption is still good and safe but there are (maybe) already better alternatives than this library or\nCryptoJS itself. If you require really high security, you should invest more time for what is suitable for you.\n\nAlso, there's a good article about PHP issues/info related to this\nlibrary: https://stackoverflow.com/questions/16600708/how-do-you-encrypt-and-decrypt-a-php-string/30159120#30159120\n\n## Alternatives - ASCON\n\nYou may wonder if there are alternatives to AES encryption that you can use in PHP/JS. ASCON is a newer, lightweight cipher that have been selected in 2023 by the [NIST](https://csrc.nist.gov/projects/lightweight-cryptography) as the new standard for lightweight cryptography, which may suite your needs. I have created libraries for both PHP and JS which you can find at https://github.com/brainfoolong/php-ascon and https://github.com/brainfoolong/js-ascon\n\n## Requirements\n\n* PHP with OpenSSL Support: http://php.net/manual/en/openssl.installation.php\n* Does not work with following php.ini option enabled: http://php.net/manual/en/mbstring.overload.php\n\n## Changelog\n\n* 2.3.0 - Dez 2023\n    * upgraded CryptoJS to v4.2.0\n\n* 2.2.0 - 13. June 2023\n    * fixed implicit true to 1 conversion by using proper OPENSSL flag (thx @benjumanji)\n    * added tests for php and js\n    * added a js console warning for passphrases with non ASCII characters, as it is and was never supported\n    * minor improved php decrypt to avoid one useless hash cycle\n\n* 2.1.1 - 15. January 2021\n    * just a few documentation and composer fixes\n* 2.1.0 - 30. December 2020\n    * added quick decrypt and encrypt functions: `CryptoJSAesJson.encrypt()` and `CryptoJSAesJson.decrypt()` - See\n      examples for more information\n* 2.x.x - 7. April 2020\n    * Upgraded project to namespaces\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainfoolong%2Fcryptojs-aes-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainfoolong%2Fcryptojs-aes-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainfoolong%2Fcryptojs-aes-php/lists"}