Socket
Socket
Sign inDemoInstall

cryptorjs

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 3.0.0

src/constants.js

19

CHANGELOG.md

@@ -7,2 +7,21 @@ # Change Log

## [3.0.0] - 2018-09-03
- Changed cipher method from `createCipher` to `createCipheriv` for node deprecation
- **Breaking changes** now support only this ciphers:
- aes-256-cbc
- aes-256-cbc-hmac-sha1
- aes-256-cbc-hmac-sha256
- aes-256-cfb
- aes-256-cfb1
- aes-256-cfb8
- aes-256-ctr
- aes-256-ofb
- aes256
- camellia-256-cbc
- camellia-256-cfb
- camellia-256-cfb1
- camellia-256-cfb8
- camellia-256-ofb
- camellia256
## [2.1.0] - 2017-12-03

@@ -9,0 +28,0 @@ - Added static method `hasHash`

5

package.json
{
"name": "cryptorjs",
"version": "2.1.0",
"version": "3.0.0",
"description": "Encrypt and decrypt string, number and object using a key",

@@ -14,3 +14,4 @@ "main": "index.js",

"postversion": "npm publish && git push && git push --tags",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"mocha:test": "mocha test"
},

@@ -17,0 +18,0 @@ "repository": {

25

README.md

@@ -44,12 +44,12 @@ <div align="center">

### With a cipher
For example using "blowfish" cipher
For example using "camellia-256-cfb1" cipher
```javascript
var cryptorjs = require('cryptorjs');
var myCryptor = new cryptorjs('yourSecretKey', 'blowfish');
var myCryptor = new cryptorjs('yourSecretKey', 'camellia-256-cfb1');
var encoded = myCryptor.encode('myExampleString');
// => 'd21c35352099eac53a129a414530c162'
// => 'ac3277ba5c3f433d6b7ea70979fe55'
var decoded = myCryptor.decode('d21c35352099eac53a129a414530c162');
var decoded = myCryptor.decode('ac3277ba5c3f433d6b7ea70979fe55');
// => 'myExampleString'

@@ -92,2 +92,19 @@ ```

### Supported ciphers (since 3.0.0)
- aes-256-cbc
- aes-256-cbc-hmac-sha1
- aes-256-cbc-hmac-sha256
- aes-256-cfb
- aes-256-cfb1
- aes-256-cfb8
- aes-256-ctr
- aes-256-ofb
- aes256
- camellia-256-cbc
- camellia-256-cfb
- camellia-256-cfb1
- camellia-256-cfb8
- camellia-256-ofb
- camellia256
## License

@@ -94,0 +111,0 @@ Cryptorjs is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

@@ -8,3 +8,3 @@ /**

const deprecate = require('depreca');
const {ALGORITHM} = require('./constants');
/**

@@ -20,11 +20,29 @@ * Cryptor class

*/
constructor(key, algorithm = 'aes-256-ctr'){
if(typeof key === 'undefined')
throw new Error('required key');
constructor(key, algorithm = 'aes-256-ctr') {
if (typeof key !== 'string')
throw new Error('required an string key');
if(key === '')
if (key === '')
throw new Error('key cannot be empty');
this.algorithm = algorithm;
this.key = key;
if (!ALGORITHM.includes(algorithm))
throw new Error(`algorithm ${algorithm} not supported, use those available: ${ALGORITHM.join(', ')}`);
// Transform to 32 chars
key = this.constructor.hash(key, 'md5');
Object.defineProperties(this, {
algorithm: {
value: algorithm
},
key: {
value: key
},
iv: {
value: key.substr(16)
},
options: {
value: {}
}
});
}

@@ -39,3 +57,3 @@

str = helper.normalizeInput(str);
let cipher = crypto.createCipher(this.algorithm, this.key);
const cipher = crypto.createCipheriv(this.algorithm, this.key, this.iv, this.options);
return cipher.update(str, 'utf8', 'hex') + cipher.final('hex');

@@ -51,4 +69,4 @@ }

str = helper.normalizeInput(str);
let decipher = crypto.createDecipher(this.algorithm, this.key);
let decoded = decipher.update(str, 'hex', 'utf8') + decipher.final('utf8');
const decipher = crypto.createDecipheriv(this.algorithm, this.key, this.iv, this.options);
const decoded = decipher.update(str, 'hex', 'utf8') + decipher.final('utf8');
return helper.normalizeOutput(decoded);

@@ -61,3 +79,3 @@ }

*/
static getCiphers(){
static getCiphers() {
return crypto.getCiphers();

@@ -70,3 +88,3 @@ }

*/
static getHashes(){
static getHashes() {
return crypto.getHashes();

@@ -81,3 +99,3 @@ }

*/
static md5(str){
static md5(str) {
deprecate('md5 is deprecated, use hash method instead. e.g. hash("your string", "md5")');

@@ -93,3 +111,3 @@ return crypto.createHash('md5').update(str).digest('hex');

*/
static sha1(str){
static sha1(str) {
deprecate('sha1 is deprecated, use hash method instead. e.g. hash("your string", "sha1")');

@@ -105,4 +123,4 @@ return crypto.createHash('sha1').update(str).digest('hex');

*/
static hash(str, hash){
if(Cryptor.hasHash(hash)){
static hash(str, hash) {
if (Cryptor.hasHash(hash)) {
return crypto.createHash(hash).update(str).digest('hex');

@@ -119,3 +137,3 @@ } else {

*/
static hasHash(hash){
static hasHash(hash) {
return Cryptor.getHashes().indexOf(hash) !== -1;

@@ -122,0 +140,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc