Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crypto-es

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-es - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

10

CHANGELOG.md

@@ -18,2 +18,10 @@ ## 1.0.0

- Update README.md.
- Update README.md.
## 1.1.0
**2019-07-12**
- Add support for ArrayBuffer and TypedArray.
- Change some inner object names in case of confusion for partially import.

4

lib/aes.js

@@ -74,3 +74,3 @@ import {

*/
export class AES extends BlockCipher {
export class AESAlgo extends BlockCipher {
constructor(...args) {

@@ -284,2 +284,2 @@ super(...args);

*/
export const AESFunc = BlockCipher._createHelper(AES);
export const AES = BlockCipher._createHelper(AESAlgo);

@@ -9,3 +9,3 @@ /* eslint-disable no-use-before-define */

import { Base64 } from './enc-base64.js';
import { EvpKDF } from './evpkdf.js';
import { EvpKDFAlgo } from './evpkdf.js';

@@ -774,3 +774,3 @@ /**

// Derive key and IV
const key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, _salt);
const key = EvpKDFAlgo.create({ keySize: keySize + ivSize }).compute(password, _salt);

@@ -777,0 +777,0 @@ // Separate key and IV

@@ -76,4 +76,41 @@ /* eslint-disable no-use-before-define */

this.words = words;
this.sigBytes = sigBytes;
let typedArray = words;
// Convert buffers to uint8
if (typedArray instanceof ArrayBuffer) {
typedArray = new Uint8Array(typedArray);
}
// Convert other array views to uint8
if (
typedArray instanceof Int8Array
|| typedArray instanceof Uint8ClampedArray
|| typedArray instanceof Int16Array
|| typedArray instanceof Uint16Array
|| typedArray instanceof Int32Array
|| typedArray instanceof Uint32Array
|| typedArray instanceof Float32Array
|| typedArray instanceof Float64Array
) {
typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
}
// Handle Uint8Array
if (typedArray instanceof Uint8Array) {
// Shortcut
const typedArrayByteLength = typedArray.byteLength;
// Extract bytes
const _words = [];
for (let i = 0; i < typedArrayByteLength; i += 1) {
_words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
}
// Initialize this word array
this.words = _words;
this.sigBytes = typedArrayByteLength;
} else {
// Else call normal init
this.words = words;
this.sigBytes = sigBytes;
}
}

@@ -80,0 +117,0 @@

@@ -5,3 +5,3 @@ import {

} from './core.js';
import { MD5 } from './md5.js';
import { MD5Algo } from './md5.js';

@@ -12,3 +12,3 @@ /**

*/
export class EvpKDF extends Base {
export class EvpKDFAlgo extends Base {
/**

@@ -39,3 +39,3 @@ * Initializes a newly created key derivation function.

keySize: 128 / 32,
hasher: MD5,
hasher: MD5Algo,
iterations: 1,

@@ -114,2 +114,2 @@ },

*/
export const EvpKDFFunc = (password, salt, cfg) => EvpKDF.create(cfg).compute(password, salt);
export const EvpKDF = (password, salt, cfg) => EvpKDFAlgo.create(cfg).compute(password, salt);

@@ -31,26 +31,26 @@ import {

import { HMAC } from './hmac.js';
import { MD5, MD5Func, HmacMD5Func } from './md5.js';
import { SHA1, SHA1Func, HmacSHA1Func } from './sha1.js';
import { SHA224, SHA224Func, HmacSHA224Func } from './sha224.js';
import { SHA256, SHA256Func, HmacSHA256Func } from './sha256.js';
import { SHA384, SHA384Func, HmacSHA384Func } from './sha384.js';
import { SHA512, SHA512Func, HmacSHA512Func } from './sha512.js';
import { SHA3, SHA3Func, HmacSHA3Func } from './sha3.js';
import { RIPEMD160, RIPEMD160Func, HmacRIPEMD160Func } from './ripemd160.js';
import { PBKDF2, PBKDF2Func } from './pbkdf2.js';
import { EvpKDF, EvpKDFFunc } from './evpkdf.js';
import { AES, AESFunc } from './aes.js';
import { MD5Algo, MD5, HmacMD5 } from './md5.js';
import { SHA1Algo, SHA1, HmacSHA1 } from './sha1.js';
import { SHA224Algo, SHA224, HmacSHA224 } from './sha224.js';
import { SHA256Algo, SHA256, HmacSHA256 } from './sha256.js';
import { SHA384Algo, SHA384, HmacSHA384 } from './sha384.js';
import { SHA512Algo, SHA512, HmacSHA512 } from './sha512.js';
import { SHA3Algo, SHA3, HmacSHA3 } from './sha3.js';
import { RIPEMD160Algo, RIPEMD160, HmacRIPEMD160 } from './ripemd160.js';
import { PBKDF2Algo, PBKDF2 } from './pbkdf2.js';
import { EvpKDFAlgo, EvpKDF } from './evpkdf.js';
import { AESAlgo, AES } from './aes.js';
import {
DESAlgo,
DES,
DESFunc,
TripleDESAlgo,
TripleDES,
TripleDESFunc,
} from './tripledes.js';
import { Rabbit, RabbitFunc } from './rabbit.js';
import { RabbitLegacy, RabbitLegacyFunc } from './rabbit-legacy.js';
import { RabbitAlgo, Rabbit } from './rabbit.js';
import { RabbitLegacyAlgo, RabbitLegacy } from './rabbit-legacy.js';
import {
RC4Algo,
RC4,
RC4Func,
RC4DropAlgo,
RC4Drop,
RC4DropFunc,
} from './rc4.js';

@@ -101,21 +101,21 @@ import { CFB } from './mode-cfb.js';

HMAC,
MD5,
SHA1,
SHA224,
SHA256,
SHA384,
SHA512,
SHA3,
RIPEMD160,
MD5: MD5Algo,
SHA1: SHA1Algo,
SHA224: SHA224Algo,
SHA256: SHA256Algo,
SHA384: SHA384Algo,
SHA512: SHA512Algo,
SHA3: SHA3Algo,
RIPEMD160: RIPEMD160Algo,
PBKDF2,
EvpKDF,
PBKDF2: PBKDF2Algo,
EvpKDF: EvpKDFAlgo,
AES,
DES,
TripleDES,
Rabbit,
RabbitLegacy,
RC4,
RC4Drop,
AES: AESAlgo,
DES: DESAlgo,
TripleDES: TripleDESAlgo,
Rabbit: RabbitAlgo,
RabbitLegacy: RabbitLegacyAlgo,
RC4: RC4Algo,
RC4Drop: RC4DropAlgo,
},

@@ -150,29 +150,29 @@

MD5: MD5Func,
HmacMD5: HmacMD5Func,
SHA1: SHA1Func,
HmacSHA1: HmacSHA1Func,
SHA224: SHA224Func,
HmacSHA224: HmacSHA224Func,
SHA256: SHA256Func,
HmacSHA256: HmacSHA256Func,
SHA384: SHA384Func,
HmacSHA384: HmacSHA384Func,
SHA512: SHA512Func,
HmacSHA512: HmacSHA512Func,
SHA3: SHA3Func,
HmacSHA3: HmacSHA3Func,
RIPEMD160: RIPEMD160Func,
HmacRIPEMD160: HmacRIPEMD160Func,
MD5,
HmacMD5,
SHA1,
HmacSHA1,
SHA224,
HmacSHA224,
SHA256,
HmacSHA256,
SHA384,
HmacSHA384,
SHA512,
HmacSHA512,
SHA3,
HmacSHA3,
RIPEMD160,
HmacRIPEMD160,
PBKDF2: PBKDF2Func,
EvpKDF: EvpKDFFunc,
PBKDF2,
EvpKDF,
AES: AESFunc,
DES: DESFunc,
TripleDES: TripleDESFunc,
Rabbit: RabbitFunc,
RabbitLegacy: RabbitLegacyFunc,
RC4: RC4Func,
RC4Drop: RC4DropFunc,
AES,
DES,
TripleDES,
Rabbit,
RabbitLegacy,
RC4,
RC4Drop,
};

@@ -37,3 +37,3 @@ import {

*/
export class MD5 extends Hasher {
export class MD5Algo extends Hasher {
_doReset() {

@@ -232,3 +232,3 @@ this._hash = new WordArray([

*/
export const MD5Func = Hasher._createHelper(MD5);
export const MD5 = Hasher._createHelper(MD5Algo);

@@ -249,2 +249,2 @@ /**

*/
export const HmacMD5Func = Hasher._createHmacHelper(MD5);
export const HmacMD5 = Hasher._createHmacHelper(MD5Algo);

@@ -5,3 +5,3 @@ import {

} from './core.js';
import { SHA1 } from './sha1.js';
import { SHA1Algo } from './sha1.js';
import { HMAC } from './hmac.js';

@@ -12,3 +12,3 @@

*/
export class PBKDF2 extends Base {
export class PBKDF2Algo extends Base {
/**

@@ -39,3 +39,3 @@ * Initializes a newly created key derivation function.

keySize: 128 / 32,
hasher: SHA1,
hasher: SHA1Algo,
iterations: 1,

@@ -125,2 +125,2 @@ },

*/
export const PBKDF2Func = (password, salt, cfg) => PBKDF2.create(cfg).compute(password, salt);
export const PBKDF2 = (password, salt, cfg) => PBKDF2Algo.create(cfg).compute(password, salt);

@@ -65,3 +65,3 @@ import {

*/
export class RabbitLegacy extends StreamCipher {
export class RabbitLegacyAlgo extends StreamCipher {
constructor(...args) {

@@ -176,2 +176,2 @@ super(...args);

*/
export const RabbitLegacyFunc = StreamCipher._createHelper(RabbitLegacy);
export const RabbitLegacy = StreamCipher._createHelper(RabbitLegacyAlgo);

@@ -61,3 +61,3 @@ import {

*/
export class Rabbit extends StreamCipher {
export class RabbitAlgo extends StreamCipher {
constructor(...args) {

@@ -178,2 +178,2 @@ super(...args);

*/
export const RabbitFunc = StreamCipher._createHelper(Rabbit);
export const Rabbit = StreamCipher._createHelper(RabbitAlgo);

@@ -35,3 +35,3 @@ import {

*/
export class RC4 extends StreamCipher {
export class RC4Algo extends StreamCipher {
constructor(...args) {

@@ -90,3 +90,3 @@ super(...args);

*/
export const RC4Func = StreamCipher._createHelper(RC4);
export const RC4 = StreamCipher._createHelper(RC4Algo);

@@ -96,3 +96,3 @@ /**

*/
export class RC4Drop extends RC4 {
export class RC4DropAlgo extends RC4Algo {
constructor(...args) {

@@ -127,2 +127,2 @@ super(...args);

*/
export const RC4DropFunc = StreamCipher._createHelper(RC4Drop);
export const RC4Drop = StreamCipher._createHelper(RC4DropAlgo);

@@ -72,3 +72,3 @@ /** @preserve

*/
export class RIPEMD160 extends Hasher {
export class RIPEMD160Algo extends Hasher {
_doReset() {

@@ -227,3 +227,3 @@ this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);

*/
export const RIPEMD160Func = Hasher._createHelper(RIPEMD160);
export const RIPEMD160 = Hasher._createHelper(RIPEMD160Algo);

@@ -244,2 +244,2 @@ /**

*/
export const HmacRIPEMD160Func = Hasher._createHmacHelper(RIPEMD160);
export const HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160Algo);

@@ -12,3 +12,3 @@ import {

*/
export class SHA1 extends Hasher {
export class SHA1Algo extends Hasher {
_doReset() {

@@ -113,3 +113,3 @@ this._hash = new WordArray([

*/
export const SHA1Func = Hasher._createHelper(SHA1);
export const SHA1 = Hasher._createHelper(SHA1Algo);

@@ -130,2 +130,2 @@ /**

*/
export const HmacSHA1Func = Hasher._createHmacHelper(SHA1);
export const HmacSHA1 = Hasher._createHmacHelper(SHA1Algo);
import { WordArray } from './core.js';
import { SHA256 } from './sha256.js';
import { SHA256Algo } from './sha256.js';

@@ -7,3 +7,3 @@ /**

*/
export class SHA224 extends SHA256 {
export class SHA224Algo extends SHA256Algo {
_doReset() {

@@ -45,3 +45,3 @@ this._hash = new WordArray([

*/
export const SHA224Func = SHA256._createHelper(SHA224);
export const SHA224 = SHA256Algo._createHelper(SHA224Algo);

@@ -62,2 +62,2 @@ /**

*/
export const HmacSHA224Func = SHA256._createHmacHelper(SHA224);
export const HmacSHA224 = SHA256Algo._createHmacHelper(SHA224Algo);

@@ -45,3 +45,3 @@ import {

*/
export class SHA256 extends Hasher {
export class SHA256Algo extends Hasher {
_doReset() {

@@ -156,3 +156,3 @@ this._hash = new WordArray(H.slice(0));

*/
export const SHA256Func = Hasher._createHelper(SHA256);
export const SHA256 = Hasher._createHelper(SHA256Algo);

@@ -173,2 +173,2 @@ /**

*/
export const HmacSHA256Func = Hasher._createHmacHelper(SHA256);
export const HmacSHA256 = Hasher._createHmacHelper(SHA256Algo);

@@ -69,3 +69,3 @@ import {

*/
export class SHA3 extends Hasher {
export class SHA3Algo extends Hasher {
constructor(cfg) {

@@ -280,3 +280,3 @@ /**

*/
export const SHA3Func = Hasher._createHelper(SHA3);
export const SHA3 = Hasher._createHelper(SHA3Algo);

@@ -297,2 +297,2 @@ /**

*/
export const HmacSHA3Func = Hasher._createHmacHelper(SHA3);
export const HmacSHA3 = Hasher._createHmacHelper(SHA3Algo);

@@ -5,3 +5,3 @@ import {

} from './x64-core.js';
import { SHA512 } from './sha512.js';
import { SHA512Algo } from './sha512.js';

@@ -11,3 +11,3 @@ /**

*/
export class SHA384 extends SHA512 {
export class SHA384Algo extends SHA512Algo {
_doReset() {

@@ -49,3 +49,3 @@ this._hash = new X64WordArray([

*/
export const SHA384Func = SHA512._createHelper(SHA384);
export const SHA384 = SHA512Algo._createHelper(SHA384Algo);

@@ -66,2 +66,2 @@ /**

*/
export const HmacSHA384Func = SHA512._createHmacHelper(SHA384);
export const HmacSHA384 = SHA512Algo._createHmacHelper(SHA384Algo);

@@ -100,3 +100,3 @@ import { Hasher } from './core.js';

*/
export class SHA512 extends Hasher {
export class SHA512Algo extends Hasher {
constructor() {

@@ -354,3 +354,3 @@ super();

*/
export const SHA512Func = Hasher._createHelper(SHA512);
export const SHA512 = Hasher._createHelper(SHA512Algo);

@@ -371,2 +371,2 @@ /**

*/
export const HmacSHA512Func = Hasher._createHmacHelper(SHA512);
export const HmacSHA512 = Hasher._createHmacHelper(SHA512Algo);

@@ -588,3 +588,3 @@ import {

*/
export class DES extends BlockCipher {
export class DESAlgo extends BlockCipher {
constructor(...args) {

@@ -714,3 +714,3 @@ super(...args);

*/
export const DESFunc = BlockCipher._createHelper(DES);
export const DES = BlockCipher._createHelper(DESAlgo);

@@ -720,3 +720,3 @@ /**

*/
export class TripleDES extends BlockCipher {
export class TripleDESAlgo extends BlockCipher {
constructor(...args) {

@@ -736,5 +736,5 @@ super(...args);

// Create DES instances
this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
this._des1 = DESAlgo.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
this._des2 = DESAlgo.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
this._des3 = DESAlgo.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
}

@@ -763,2 +763,2 @@

*/
export const TripleDESFunc = BlockCipher._createHelper(TripleDES);
export const TripleDES = BlockCipher._createHelper(TripleDESAlgo);
{
"name": "crypto-es",
"version": "1.0.2",
"version": "1.1.0",
"description": "A cryptography algorithms library",

@@ -9,2 +9,5 @@ "keywords": [

"cipher",
"ArrayBuffer",
"TypedArray",
"file",
"ECMAScript",

@@ -52,10 +55,9 @@ "ES6",

"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"eslint": "5.3.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "2.14.0",
"jest": "^23.6.0"
"@babel/core": "^7.5.4",
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
"babel-jest": "^24.8.0",
"eslint": "^6.0.1",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.0",
"jest": "^24.8.0"
},

@@ -62,0 +64,0 @@ "jest": {

@@ -7,2 +7,3 @@ # CryptoES

- Witten in latest ECMAScript Standard
- Support partially import

@@ -23,10 +24,18 @@ ## Usage

As It's written in ECMAScript, including the ECMAScript Module, you may need [Babel](https://babeljs.io/) and [Webpack](https://webpack.js.org/) for browser, or [Loader hook](https://nodejs.org/dist/latest-v10.x/docs/api/esm.html#esm_loader_hooks) for node.
You may need [Babel](https://babeljs.io/) and [Webpack](https://webpack.js.org/) for old IE browsers, or [Loader hook](https://nodejs.org/dist/latest-v10.x/docs/api/esm.html#esm_loader_hooks) for Node.js.
Then you can import CryptoES as a regular ECMAScript module:
Then you can import CryptoES:
```
import CryptoES from 'crypto-es';
const hash = CryptoES.MD5("Message");
```
Or partially import the functions to reduce the package weight:
```
import { MD5 } from 'crypto-es/md5.js';
const hash = MD5("Message");
```
## Quick-start Guide

@@ -374,2 +383,29 @@

const utf16 = CryptoES.enc.Utf16LE.stringify(words);
```
```
### ArrayBuffer and TypedArray
WordArray creator could recive an ArrayBuffer or TypedArray so that CryptoES algorisms could apply to them:
```
const words = CryptoES.lib.WordArray.create(new ArrayBuffer(8));
const rst = CryptoES.AES.encrypt(words, 'Secret Passphrase')
```
**NOTE**: ArrayBuffer could not directly passed to algorisms, you should change them to WordArray first.
With this, encrypting files would be easier:
```
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function () {
const arrayBuffer = reader.result;
const words = CryptoES.lib.WordArray.create(arrayBuffer);
const rst = CryptoES.AES.encrypt(words, 'Secret Passphrase')
...
};
```
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc