SimpleCrypto is a JavaScript library that simplify the process of encryption and decryption of JavaScript objects, as simple as just calling encrypt()
and decrypt()
function. This library implements brix's crypto-js library. This library is pure JavaScript library built with TypeScript targeting CommonJS ECMAScript 5 (ES5), so it is compatible with most NodeJS back-end applications or JavaScript front-end (client browser).
v2.3.0: New Algorithm
SimpleCrypto v2.3.0 onward will use a new algorithm, because the older one was vulnerable to chosen cipher attack. Any data that encrypted using v2.2.0 and earlier will NOT be able to be decrypted using v2.3.0 onward; vice versa: data encrypted using v2.3.0 onward will NOT be able to be decrypted using v2.2.0 and earlier.
v3.0.0: New Native Crypto Module
SimpleCrypto v3.0.0 onward will use new crypto-js
dependency version ^4.0.0
. This version of crypto-js
replaces Math.random()
method with native crypto module. Because of this, SimpleCrypto might not be able to run on some environments without native crypto module support, such as IE 10 (and earlier) or React Native.
Please read more here.
What's New in 3.0.1 (latest current)
- Upgrade
crypto-js
dependency to version4.1.1
. - Improving typings.
What's New in 2.5.1 (latest legacy)
- Improving typings.
For full change-log, please refer to CHANGELOG file.
This library is available through jsDelivr CDN and package manager (like npm or yarn).
To get started, add SimpleCrypto script to your HTML page. Only legacy version of SimpleCrypto is supported.
<head>
<!-- Another line -->
<script src="//cdn.jsdelivr.net/npm/simple-crypto-js@legacy/dist/SimpleCrypto.min.js"></script>
<!-- Another line -->
</head>
Then, your script section, you may use SimpleCrypto
as Class to create a new SimpleCrypto instance.
<body>
<!-- Another line -->
<script lang="js">
var simpleCrypto = new SimpleCrypto("a very secret key")
<!-- Do your cryptographic logic here -->
</script>
<!-- Another line -->
</body>
If you are using NodeJS, add simple-crypto-js
as your project dependency.
# If you're using NPM
npm install --save simple-crypto-js
# If you're using Yarn
yarn add simple-crypto-js
Then, include SimpleCrypto your project.
var SimpleCrypto = require("simple-crypto-js").default
If you are using Babel or TypeScript that support import statement, you could go that way.
import SimpleCrypto from "simple-crypto-js"
Full documentation about SimpleCrypto API is available here.
Written in TypeScript, built into ECMAScript 5 using the TypeScript compiler and webpack bundler.
To contribute, simply fork this project, and issue a pull request. However, before issuing a pull request, you have to make sure that your changes will not break current API, its parameter and its expected output.
You may test your changes by running the test script.
npm run test
If all tests were passed, you are good to go.
We use Semantic Versioning for version management. For the versions available, see the tags on this repository.
- Danang Galuh Tegar Prasetyo - Initial work - danang-id
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details
- This library was developed to support and simplify the Secure Cookies library.
- Made available by open source and of course brix's crypto-js library