File tree 2 files changed +6
-0
lines changed
2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = function (keyPair, options) {
8
8
encrypt : function ( buffer , usePrivate ) {
9
9
var m , c ;
10
10
if ( usePrivate ) {
11
+ /* Type 1: zeros padding for private key encrypt */
11
12
m = new BigInteger ( pkcs1Scheme . encPad ( buffer , { type : 1 } ) ) ;
12
13
c = keyPair . $doPrivate ( m ) ;
13
14
} else {
@@ -22,6 +23,7 @@ module.exports = function (keyPair, options) {
22
23
23
24
if ( usePublic ) {
24
25
m = keyPair . $doPublic ( c ) ;
26
+ /* Type 1: zeros padding for private key decrypt */
25
27
return pkcs1Scheme . encUnPad ( m . toBuffer ( keyPair . encryptedDataLength ) , { type : 1 } ) ;
26
28
} else {
27
29
m = keyPair . $doPrivate ( c ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ module.exports.makeScheme = function (key, options) {
50
50
throw new Error ( "Message too long for RSA (n=" + this . key . encryptedDataLength + ", l=" + buffer . length + ")" ) ;
51
51
}
52
52
53
+ /* Type 1: zeros padding for private key encrypt */
53
54
if ( options . type === 1 ) {
54
55
filled = new Buffer ( this . key . encryptedDataLength - buffer . length - 1 ) ;
55
56
filled . fill ( 0xff , 0 , filled . length - 1 ) ;
@@ -58,6 +59,7 @@ module.exports.makeScheme = function (key, options) {
58
59
59
60
return Buffer . concat ( [ filled , buffer ] ) ;
60
61
} else {
62
+ /* random padding for public key encrypt */
61
63
filled = new Buffer ( this . key . encryptedDataLength - buffer . length ) ;
62
64
filled [ 0 ] = 0 ;
63
65
filled [ 1 ] = 2 ;
@@ -88,6 +90,7 @@ module.exports.makeScheme = function (key, options) {
88
90
return null ;
89
91
}
90
92
93
+ /* Type 1: zeros padding for private key decrypt */
91
94
if ( options . type === 1 ) {
92
95
if ( buffer [ 0 ] !== 0 && buffer [ 1 ] !== 1 ) {
93
96
return null ;
@@ -99,6 +102,7 @@ module.exports.makeScheme = function (key, options) {
99
102
}
100
103
}
101
104
} else {
105
+ /* random padding for public key decrypt */
102
106
if ( buffer [ 0 ] !== 0 && buffer [ 1 ] !== 2 ) {
103
107
return null ;
104
108
}
You can’t perform that action at this time.
0 commit comments