This commit is contained in:
Magnus von Wachenfeldt 2021-08-26 14:35:07 +02:00
parent 1c90efecc6
commit 4f73cdb7af
Signed by: magnus
GPG Key ID: A469F7D71D09F795
4 changed files with 1 additions and 140 deletions

View File

@ -1,17 +1,7 @@
var crypt = require('crypto');
module.exports = {
getEngine: function (keyPair, options) {
var engine = require('./js.js');
if (options.environment === 'node') {
if (typeof crypt.publicEncrypt === 'function' && typeof crypt.privateDecrypt === 'function') {
if (typeof crypt.privateEncrypt === 'function' && typeof crypt.publicDecrypt === 'function') {
engine = require('./io.js');
} else {
engine = require('./node12.js');
}
}
}
return engine(keyPair, options);
}
};

View File

@ -1,72 +0,0 @@
var crypto = require('crypto');
var constants = require('constants');
var schemes = require('../schemes/schemes.js');
module.exports = function (keyPair, options) {
var pkcs1Scheme = schemes.pkcs1.makeScheme(keyPair, options);
return {
encrypt: function (buffer, usePrivate) {
var padding;
if (usePrivate) {
padding = constants.RSA_PKCS1_PADDING;
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
return crypto.privateEncrypt({
key: options.rsaUtils.exportKey('private'),
padding: padding
}, buffer);
} else {
padding = constants.RSA_PKCS1_OAEP_PADDING;
if (options.encryptionScheme === 'pkcs1') {
padding = constants.RSA_PKCS1_PADDING;
}
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
var data = buffer;
if (padding === constants.RSA_NO_PADDING) {
data = pkcs1Scheme.pkcs0pad(buffer);
}
return crypto.publicEncrypt({
key: options.rsaUtils.exportKey('public'),
padding: padding
}, data);
}
},
decrypt: function (buffer, usePublic) {
var padding;
if (usePublic) {
padding = constants.RSA_PKCS1_PADDING;
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
return crypto.publicDecrypt({
key: options.rsaUtils.exportKey('public'),
padding: padding
}, buffer);
} else {
padding = constants.RSA_PKCS1_OAEP_PADDING;
if (options.encryptionScheme === 'pkcs1') {
padding = constants.RSA_PKCS1_PADDING;
}
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
var res = crypto.privateDecrypt({
key: options.rsaUtils.exportKey('private'),
padding: padding
}, buffer);
if (padding === constants.RSA_NO_PADDING) {
return pkcs1Scheme.pkcs0unpad(res);
}
return res;
}
}
};
};

View File

@ -1,56 +0,0 @@
var crypto = require('crypto');
var constants = require('constants');
var schemes = require('../schemes/schemes.js');
module.exports = function (keyPair, options) {
var jsEngine = require('./js.js')(keyPair, options);
var pkcs1Scheme = schemes.pkcs1.makeScheme(keyPair, options);
return {
encrypt: function (buffer, usePrivate) {
if (usePrivate) {
return jsEngine.encrypt(buffer, usePrivate);
}
var padding = constants.RSA_PKCS1_OAEP_PADDING;
if (options.encryptionScheme === 'pkcs1') {
padding = constants.RSA_PKCS1_PADDING;
}
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
var data = buffer;
if (padding === constants.RSA_NO_PADDING) {
data = pkcs1Scheme.pkcs0pad(buffer);
}
return crypto.publicEncrypt({
key: options.rsaUtils.exportKey('public'),
padding: padding
}, data);
},
decrypt: function (buffer, usePublic) {
if (usePublic) {
return jsEngine.decrypt(buffer, usePublic);
}
var padding = constants.RSA_PKCS1_OAEP_PADDING;
if (options.encryptionScheme === 'pkcs1') {
padding = constants.RSA_PKCS1_PADDING;
}
if (options.encryptionSchemeOptions && options.encryptionSchemeOptions.padding) {
padding = options.encryptionSchemeOptions.padding;
}
var res = crypto.privateDecrypt({
key: options.rsaUtils.exportKey('private'),
padding: padding
}, buffer);
if (padding === constants.RSA_NO_PADDING) {
return pkcs1Scheme.pkcs0unpad(res);
}
return res;
}
};
};

View File

@ -4,7 +4,6 @@
var BigInteger = require('../libs/jsbn');
var crypt = require('crypto');
var constants = require('constants');
var SIGN_INFO_HEAD = {
md2: Buffer.from('3020300c06082a864886f70d020205000410', 'hex'),
md5: Buffer.from('3020300c06082a864886f70d020505000410', 'hex'),