Socket
Socket
Sign inDemoInstall

crypto-browserify

Package Overview
Dependencies
4
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

pbkdf2.js

10

create-hash.js

@@ -0,7 +1,4 @@

var createHash = require('sha.js')
var algs = {
sha1 : require('sha.js/sha1'),
sha256 : require('sha.js/sha256'),
md5 : toConstructor(require('./md5'))
}
var md5 = toConstructor(require('./md5'))

@@ -29,3 +26,4 @@ function toConstructor (fn) {

module.exports = function (alg) {
return new algs[alg]()
if('md5' === alg) return new md5()
return createHash(alg)
}

52

create-hmac.js

@@ -6,8 +6,13 @@ var createHash = require('./create-hash')

function hmac(fn, key, data) {
if(!Buffer.isBuffer(key)) key = new Buffer(key)
if(!Buffer.isBuffer(data)) data = new Buffer(data)
module.exports = Hmac
function Hmac (alg, key) {
if(!(this instanceof Hmac)) return new Hmac(alg, key)
this._opad = opad
this._alg = alg
key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key
if(key.length > blocksize) {
key = fn(key)
key = createHash(alg).update(key).digest()
} else if(key.length < blocksize) {

@@ -17,3 +22,5 @@ key = Buffer.concat([key, zeroBuffer], blocksize)

var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
var ipad = this._ipad = new Buffer(blocksize)
var opad = this._opad = new Buffer(blocksize)
for(var i = 0; i < blocksize; i++) {

@@ -24,31 +31,14 @@ ipad[i] = key[i] ^ 0x36

var hash = fn(Buffer.concat([ipad, data]))
return fn(Buffer.concat([opad, hash]))
this._hash = createHash(alg).update(ipad)
}
Hmac.prototype.update = function (data, enc) {
this._hash.update(data, enc)
return this
}
module.exports = createHmac
Hmac.prototype.digest = function (enc) {
var h = this._hash.digest()
return createHash(this._alg).update(this._opad).update(h).digest(enc)
}
function createHmac (alg, key) {
if(!Buffer.isBuffer(key)) key = new Buffer(key)
// if(!Buffer.isBuffer(data)) data = new Buffer(data)
if(key.length > blocksize) {
key = createHash(alg).update(key).digest()
} else if(key.length < blocksize) {
key = Buffer.concat([key, zeroBuffer], blocksize)
}
var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
for(var i = 0; i < blocksize; i++) {
ipad[i] = key[i] ^ 0x36
opad[i] = key[i] ^ 0x5C
}
hash = createHash(alg).update(ipad)//.update(data)
var digest = hash.digest
hash.digest = function (enc) {
var h = digest.call(hash)
return createHash(alg).update(opad).update(h).digest(enc)
}
return hash
}

@@ -32,2 +32,7 @@ var Buffer = require('buffer').Buffer

var p = require('./pbkdf2')(exports.createHmac)
exports.pbkdf2 = p.pbkdf2
exports.pbkdf2Sync = p.pbkdf2Sync
// the least I can do is make error messages for the rest of the node.js/crypto api.

@@ -42,3 +47,3 @@ each(['createCredentials'

, 'createDiffieHellman'
, 'pbkdf2'], function (name) {
], function (name) {
exports[name] = function () {

@@ -45,0 +50,0 @@ error('sorry,', name, 'is not implemented yet')

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

"description": "partial implementation of crypto for the browser",
"version": "2.0.0",
"version": "2.1.0",
"homepage": "https://github.com/dominictarr/crypto-browserify",

@@ -8,0 +8,0 @@ "repository": {

// Original code adapted from Robert Kieffer.
// details at https://github.com/broofa/node-uuid
(function() {

@@ -10,3 +12,3 @@ var _global = this;

mathRNG = function(size) {
var bytes = new Array(size);
var bytes = new Buffer(size);
var r;

@@ -24,3 +26,3 @@

whatwgRNG = function(size) {
var bytes = new Uint8Array(size);
var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array
crypto.getRandomValues(bytes);

@@ -27,0 +29,0 @@ return bytes;

@@ -6,2 +6,4 @@

var data = require('crypto').pseudoRandomBytes(256)
;['sha1', 'sha256', 'md5'].forEach(function (alg) {

@@ -18,3 +20,19 @@ console.log('alg', alg)

})
for(var i = 8; i < data.length; i += 7)
(function (i) {
var pass = data.slice(0, i)
same('createHmac('+alg+', pseudoRandomBytes('+ i + ')' , function (crypto, cb) {
var r = crypto
.createHmac(alg, pass)
.digest('hex')
console.log(r)
cb(null, r)
})
}(i))
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc