@@ -115,13 +115,13 @@ export class Crypto {
115
115
* @params hashAlgorithm The hash algorithm ('SHA2' or 'SHA3')
116
116
*/
117
117
setHashAlgorithm ( hashAlgorithm :string ) :void {
118
- this . checkHashFunction ( hashAlgorithm ) ;
118
+ Crypto . checkHashFunction ( hashAlgorithm ) ;
119
119
120
120
this . hashAlgorithm = hashAlgorithm ;
121
121
this . initialize ( ) ;
122
122
}
123
123
124
- generateNonce ( ) {
124
+ static generateNonce ( ) {
125
125
return crypto . randomBytes ( NonceSize ) ;
126
126
}
127
127
@@ -305,11 +305,11 @@ export class Crypto {
305
305
return decryptedBytes ;
306
306
}
307
307
308
- aesKeyGen ( ) {
308
+ static aesKeyGen ( ) {
309
309
return crypto . randomBytes ( AESKeyLength ) ;
310
310
}
311
311
312
- aesCFBDecryt ( key , encryptedBytes ) {
312
+ static aesCFBDecrypt ( key , encryptedBytes ) {
313
313
314
314
var iv = crypto . randomBytes ( IVLength ) ;
315
315
var aes = new aesjs . ModeOfOperation . cfb ( key , iv , IVLength ) ;
@@ -336,13 +336,13 @@ export class Crypto {
336
336
337
337
var decryptedBytes , unpaddedBytes ;
338
338
339
- decryptedBytes = this . CBCDecrypt ( key , bytes ) ;
340
- unpaddedBytes = this . PKCS7UnPadding ( decryptedBytes ) ;
339
+ decryptedBytes = Crypto . CBCDecrypt ( key , bytes ) ;
340
+ unpaddedBytes = Crypto . PKCS7UnPadding ( decryptedBytes ) ;
341
341
342
342
return unpaddedBytes ;
343
343
} ;
344
344
345
- aes256GCMDecrypt ( key :Buffer , ct :Buffer ) {
345
+ static aes256GCMDecrypt ( key :Buffer , ct :Buffer ) {
346
346
let decipher = crypto . createDecipheriv ( 'aes-256-gcm' , key , ct . slice ( 0 , GCMStandardNonceSize ) ) ;
347
347
decipher . setAuthTag ( ct . slice ( ct . length - GCMTagSize ) ) ;
348
348
let dec = decipher . update (
@@ -361,7 +361,7 @@ export class Crypto {
361
361
if ( ! info )
362
362
info = "" ;
363
363
364
- var key = this . hkdf2 ( bytesToBits ( new Buffer ( ikm ) ) , keyBitLength , bytesToBits ( salt ) , info , this . hashFunctionKeyDerivation ) ;
364
+ var key = Crypto . hkdf2 ( bytesToBits ( new Buffer ( ikm ) ) , keyBitLength , bytesToBits ( salt ) , info , this . hashFunctionKeyDerivation ) ;
365
365
366
366
return bitsToBytes ( key ) ;
367
367
@@ -394,7 +394,7 @@ export class Crypto {
394
394
throw new Error ( "Illegal level: " + this . securityLevel + " - must be either 256 or 384" ) ;
395
395
}
396
396
397
- private checkHashFunction ( hashAlgorithm : string ) {
397
+ private static checkHashFunction ( hashAlgorithm : string ) {
398
398
if ( ! _isString ( hashAlgorithm ) )
399
399
throw new Error ( "Illegal Hash function family: " + hashAlgorithm + " - must be either SHA2 or SHA3" ) ;
400
400
@@ -405,7 +405,7 @@ export class Crypto {
405
405
406
406
private initialize ( ) {
407
407
this . checkSecurityLevel ( this . securityLevel ) ;
408
- this . checkHashFunction ( this . hashAlgorithm ) ;
408
+ Crypto . checkHashFunction ( this . hashAlgorithm ) ;
409
409
410
410
this . suite = this . hashAlgorithm . toLowerCase ( ) + '-' + this . securityLevel ;
411
411
if ( this . securityLevel == CURVE_P_256_Size ) {
@@ -454,7 +454,7 @@ export class Crypto {
454
454
* @param {Object } [Hash=sjcl.hash.sha256] The hash function to use.
455
455
* @return {bitArray } derived key.
456
456
*/
457
- private hkdf2 ( ikm , keyBitLength , salt , info , Hash ) {
457
+ private static hkdf2 ( ikm , keyBitLength , salt , info , Hash ) {
458
458
var hmac , key , i , hashLen , loops , curOut , ret = [ ] ;
459
459
460
460
// Hash = Hash || sjcl.hash.sha256;
@@ -496,7 +496,7 @@ export class Crypto {
496
496
return sjcl . bitArray . clamp ( ret , keyBitLength ) ;
497
497
}
498
498
499
- private CBCDecrypt ( key , bytes ) {
499
+ private static CBCDecrypt ( key , bytes ) {
500
500
debug ( 'key length: ' , key . length ) ;
501
501
debug ( 'bytes length: ' , bytes . length ) ;
502
502
var iv = bytes . slice ( 0 , BlockSize ) ;
@@ -524,7 +524,6 @@ export class Crypto {
524
524
start += BlockSize ;
525
525
end += BlockSize ;
526
526
}
527
- ;
528
527
529
528
decryptedBytes = Buffer . concat ( decryptedBlocks ) ;
530
529
}
@@ -539,7 +538,7 @@ export class Crypto {
539
538
540
539
} ;
541
540
542
- private PKCS7UnPadding ( bytes ) {
541
+ private static PKCS7UnPadding ( bytes ) {
543
542
544
543
//last byte is the number of padded bytes
545
544
var padding = bytes . readUInt8 ( bytes . length - 1 ) ;
0 commit comments