44
55var BigInteger = require ( '../libs/jsbn' ) ;
66var crypt = require ( 'crypto' ) ;
7+ var constants = require ( 'constants' ) ;
78var SIGN_INFO_HEAD = {
89 md2 : new Buffer ( '3020300c06082a864886f70d020205000410' , 'hex' ) ,
910 md5 : new Buffer ( '3020300c06082a864886f70d020505000410' , 'hex' ) ,
@@ -34,6 +35,9 @@ module.exports.makeScheme = function (key, options) {
3435 }
3536
3637 Scheme . prototype . maxMessageLength = function ( ) {
38+ if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
39+ return this . key . encryptedDataLength ;
40+ }
3741 return this . key . encryptedDataLength - 11 ;
3842 } ;
3943
@@ -50,6 +54,13 @@ module.exports.makeScheme = function (key, options) {
5054 throw new Error ( "Message too long for RSA (n=" + this . key . encryptedDataLength + ", l=" + buffer . length + ")" ) ;
5155 }
5256
57+ if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
58+ //RSA_NO_PADDING treated like JAVA left pad with zero character
59+ filled = new Buffer ( this . key . maxMessageLength - buffer . length ) ;
60+ filled . fill ( 0 ) ;
61+ return Buffer . concat ( [ filled , buffer ] ) ;
62+ }
63+
5364 /* Type 1: zeros padding for private key encrypt */
5465 if ( options . type === 1 ) {
5566 filled = new Buffer ( this . key . encryptedDataLength - buffer . length - 1 ) ;
@@ -86,6 +97,17 @@ module.exports.makeScheme = function (key, options) {
8697 options = options || { } ;
8798 var i = 0 ;
8899
100+ if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
101+ //RSA_NO_PADDING treated like JAVA left pad with zero character
102+ var unPad ;
103+ if ( typeof buffer . lastIndexOf == "function" ) { //patch for old node version
104+ unPad = buffer . slice ( buffer . lastIndexOf ( '\0' ) + 1 , buffer . length ) ;
105+ } else {
106+ unPad = buffer . slice ( String . prototype . lastIndexOf . call ( buffer , '\0' ) + 1 , buffer . length ) ;
107+ }
108+ return unPad ;
109+ }
110+
89111 if ( buffer . length < 4 ) {
90112 return null ;
91113 }
@@ -135,6 +157,10 @@ module.exports.makeScheme = function (key, options) {
135157 } ;
136158
137159 Scheme . prototype . verify = function ( buffer , signature , signature_encoding ) {
160+ if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
161+ //RSA_NO_PADDING has no verify data
162+ return true ;
163+ }
138164 var hashAlgorithm = this . options . signingSchemeOptions . hash || DEFAULT_HASH_FUNCTION ;
139165 if ( this . options . environment === 'browser' ) {
140166 hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES [ hashAlgorithm ] || hashAlgorithm ;
0 commit comments