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.0
crypto-js
dependency to version 4.0.0
. This version of crypto-js
replaces Math.random()
method with native crypto module, and will cause breaking changes in some environments that does not support native crypto module, like IE 10 earlier and React Native. If you are affected by these changes, please use SimpleCrypto ^2.5.0
.What’s New in 2.5.0
2.4.1
, but rollback crypto-js
dependency to version 3.3.0
to maintain compatibility with environment that does not support native crypto module.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 SimpleCrypto prior to version 3.0.0 is supported.
<head>
<!-- Another line -->
<script src="//cdn.jsdelivr.net/npm/simple-crypto-js@2.5.0/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.
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