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

@stratumn/js-crypto

Package Overview
Dependencies
Maintainers
10
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stratumn/js-crypto - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

lib/keys/curve25519.js

29

lib/aes/index.js

@@ -16,3 +16,2 @@ 'use strict';

var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var iv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;

@@ -22,13 +21,18 @@ _classCallCheck(this, SymmetricKey);

this.encrypt = function (message) {
var ci = _nodeForge.cipher.createCipher('AES-CBC', _this._key);
ci.start({ iv: _this._iv });
var iv = _nodeForge.random.getBytesSync(12);
var ci = _nodeForge.cipher.createCipher('AES-GCM', _this._key);
ci.start({ iv: iv });
ci.update(_nodeForge.util.createBuffer(message));
ci.finish();
return _nodeForge.util.encode64(ci.output.bytes());
return {
ciphertext: _nodeForge.util.encode64(ci.output.bytes()),
iv: _nodeForge.util.encode64(iv),
tag: _nodeForge.util.encode64(ci.mode.tag.bytes())
};
};
this.decrypt = function (cipherText) {
var de = _nodeForge.cipher.createDecipher('AES-CBC', _this._key);
de.start({ iv: _this._iv });
this.decrypt = function (cipherText, iv, tag) {
var de = _nodeForge.cipher.createDecipher('AES-GCM', _this._key);
de.start({ iv: _nodeForge.util.decode64(iv), tag: _nodeForge.util.decode64(tag) });
de.update(_nodeForge.util.createBuffer(_nodeForge.util.decode64(cipherText)));

@@ -42,14 +46,7 @@ de.finish();

return {
key: _nodeForge.util.encode64(_this._key),
iv: _nodeForge.util.encode64(_this._iv)
key: _nodeForge.util.encode64(_this._key)
};
};
if (!key || !iv) {
this._key = _nodeForge.random.getBytesSync(32);
this._iv = _nodeForge.random.getBytesSync(16);
} else {
this._key = _nodeForge.util.decode64(key);
this._iv = _nodeForge.util.decode64(iv);
}
if (!key) this._key = _nodeForge.random.getBytesSync(32);else this._key = _nodeForge.util.decode64(key);
};

@@ -6,8 +6,4 @@ 'use strict';

});
exports.asym = exports.aes = exports.rsa = undefined;
exports.pke = exports.sig = exports.aes = undefined;
var _rsa = require('./rsa');
var rsa = _interopRequireWildcard(_rsa);
var _aes = require('./aes');

@@ -17,10 +13,14 @@

var _asym = require('./asym');
var _sig = require('./sig');
var asym = _interopRequireWildcard(_asym);
var sig = _interopRequireWildcard(_sig);
var _pke = require('./pke');
var pke = _interopRequireWildcard(_pke);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
exports.rsa = rsa;
exports.aes = aes;
exports.asym = asym;
exports.sig = sig;
exports.pke = pke;
{
"name": "@stratumn/js-crypto",
"version": "0.0.4",
"version": "0.0.5",
"description": "Browser compatible crypto",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:lib": "babel src --out-dir lib",
"test": "jest --watch",
"test:ci": "jest",
"build:lib": "babel src --out-dir lib --ignore **/*.test.js",
"prepublish": "yarn build:lib",

@@ -35,4 +36,8 @@ "lint": "eslint src/",

"eslint": "^4.19.1",
"eslint-plugin-import": "^2.12.0"
"eslint-plugin-import": "^2.12.0",
"jest": "^23.4.2"
},
"jest": {
"testURL": "http://localhost"
}
}
import { util, random, cipher } from 'node-forge';
export class SymmetricKey {
constructor(key = null, iv = null) {
if (!key || !iv) {
this._key = random.getBytesSync(32);
this._iv = random.getBytesSync(16);
} else {
this._key = util.decode64(key);
this._iv = util.decode64(iv);
}
constructor(key = null) {
if (!key) this._key = random.getBytesSync(32);
else this._key = util.decode64(key);
}
encrypt = message => {
const ci = cipher.createCipher('AES-CBC', this._key);
ci.start({ iv: this._iv });
const iv = random.getBytesSync(12);
const ci = cipher.createCipher('AES-GCM', this._key);
ci.start({ iv });
ci.update(util.createBuffer(message));
ci.finish();
return util.encode64(ci.output.bytes());
return {
ciphertext: util.encode64(ci.output.bytes()),
iv: util.encode64(iv),
tag: util.encode64(ci.mode.tag.bytes())
};
};
decrypt = cipherText => {
const de = cipher.createDecipher('AES-CBC', this._key);
de.start({ iv: this._iv });
decrypt = (cipherText, iv, tag) => {
const de = cipher.createDecipher('AES-GCM', this._key);
de.start({ iv: util.decode64(iv), tag: util.decode64(tag) });
de.update(util.createBuffer(util.decode64(cipherText)));

@@ -33,5 +33,4 @@ de.finish();

export = () => ({
key: util.encode64(this._key),
iv: util.encode64(this._iv)
key: util.encode64(this._key)
});
}

@@ -1,5 +0,5 @@

import * as rsa from './rsa';
import * as aes from './aes';
import * as asym from './asym';
import * as sig from './sig';
import * as pke from './pke';
export { rsa, aes, asym };
export { aes, sig, pke };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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