@@ -6,15 +6,15 @@ var BigInteger = require('../libs/jsbn');
6
6
var crypt = require ( 'crypto' ) ;
7
7
var constants = require ( 'constants' ) ;
8
8
var SIGN_INFO_HEAD = {
9
- md2 : new Buffer ( '3020300c06082a864886f70d020205000410' , 'hex' ) ,
10
- md5 : new Buffer ( '3020300c06082a864886f70d020505000410' , 'hex' ) ,
11
- sha1 : new Buffer ( '3021300906052b0e03021a05000414' , 'hex' ) ,
12
- sha224 : new Buffer ( '302d300d06096086480165030402040500041c' , 'hex' ) ,
13
- sha256 : new Buffer ( '3031300d060960864801650304020105000420' , 'hex' ) ,
14
- sha384 : new Buffer ( '3041300d060960864801650304020205000430' , 'hex' ) ,
15
- sha512 : new Buffer ( '3051300d060960864801650304020305000440' , 'hex' ) ,
16
- ripemd160 : new Buffer ( '3021300906052b2403020105000414' , 'hex' ) ,
17
- rmd160 : new Buffer ( '3021300906052b2403020105000414' , 'hex' )
9
+ md2 : Buffer . from ( '3020300c06082a864886f70d020205000410' , 'hex' ) ,
10
+ md5 : Buffer . from ( '3020300c06082a864886f70d020505000410' , 'hex' ) ,
11
+ sha1 : Buffer . from ( '3021300906052b0e03021a05000414' , 'hex' ) ,
12
+ sha224 : Buffer . from ( '302d300d06096086480165030402040500041c' , 'hex' ) ,
13
+ sha256 : Buffer . from ( '3031300d060960864801650304020105000420' , 'hex' ) ,
14
+ sha384 : Buffer . from ( '3041300d060960864801650304020205000430' , 'hex' ) ,
15
+ sha512 : Buffer . from ( '3051300d060960864801650304020305000440' , 'hex' ) ,
16
+ ripemd160 : Buffer . from ( '3021300906052b2403020105000414' , 'hex' ) ,
17
+ rmd160 : Buffer . from ( '3021300906052b2403020105000414' , 'hex' )
18
18
} ;
19
19
20
20
var SIGN_ALG_TO_HASH_ALIASES = {
@@ -42,7 +42,7 @@ module.exports.makeScheme = function (key, options) {
42
42
} ;
43
43
44
44
/**
45
- * Pad input Buffer to encryptedDataLength bytes, and return new Buffer
45
+ * Pad input Buffer to encryptedDataLength bytes, and return Buffer.from
46
46
* alg: PKCS#1
47
47
* @param buffer
48
48
* @returns {Buffer }
@@ -55,22 +55,22 @@ module.exports.makeScheme = function (key, options) {
55
55
}
56
56
if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
57
57
//RSA_NO_PADDING treated like JAVA left pad with zero character
58
- filled = new Buffer ( this . key . maxMessageLength - buffer . length ) ;
58
+ filled = Buffer . alloc ( this . key . maxMessageLength - buffer . length ) ;
59
59
filled . fill ( 0 ) ;
60
60
return Buffer . concat ( [ filled , buffer ] ) ;
61
61
}
62
62
63
63
/* Type 1: zeros padding for private key encrypt */
64
64
if ( options . type === 1 ) {
65
- filled = new Buffer ( this . key . encryptedDataLength - buffer . length - 1 ) ;
65
+ filled = Buffer . alloc ( this . key . encryptedDataLength - buffer . length - 1 ) ;
66
66
filled . fill ( 0xff , 0 , filled . length - 1 ) ;
67
67
filled [ 0 ] = 1 ;
68
68
filled [ filled . length - 1 ] = 0 ;
69
69
70
70
return Buffer . concat ( [ filled , buffer ] ) ;
71
71
} else {
72
72
/* random padding for public key encrypt */
73
- filled = new Buffer ( this . key . encryptedDataLength - buffer . length ) ;
73
+ filled = Buffer . alloc ( this . key . encryptedDataLength - buffer . length ) ;
74
74
filled [ 0 ] = 0 ;
75
75
filled [ 1 ] = 2 ;
76
76
var rand = crypt . randomBytes ( filled . length - 3 ) ;
@@ -165,7 +165,7 @@ module.exports.makeScheme = function (key, options) {
165
165
hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES [ hashAlgorithm ] || hashAlgorithm ;
166
166
167
167
if ( signature_encoding ) {
168
- signature = new Buffer ( signature , signature_encoding ) ;
168
+ signature = Buffer . from ( signature , signature_encoding ) ;
169
169
}
170
170
171
171
var hasher = crypt . createHash ( hashAlgorithm ) ;
@@ -199,7 +199,7 @@ module.exports.makeScheme = function (key, options) {
199
199
throw Error ( 'Key is too short for signing algorithm (' + hashAlgorithm + ')' ) ;
200
200
}
201
201
202
- var filled = new Buffer ( this . key . encryptedDataLength - data . length - 1 ) ;
202
+ var filled = Buffer . alloc ( this . key . encryptedDataLength - data . length - 1 ) ;
203
203
filled . fill ( 0xff , 0 , filled . length - 1 ) ;
204
204
filled [ 0 ] = 1 ;
205
205
filled [ filled . length - 1 ] = 0 ;
0 commit comments