import { __commonJS, __require } from "../../../../_virtual/rolldown_runtime.mjs";
import { require_schemes } from "../schemes/schemes.mjs";
import { require_js } from "./js.mjs";

//#region ../../node_modules/node-rsa/src/encryptEngines/node12.js
var require_node12 = /* @__PURE__ */ __commonJS({ "../../node_modules/node-rsa/src/encryptEngines/node12.js": ((exports, module) => {
	var crypto = __require("crypto");
	var constants = __require("constants");
	var schemes = require_schemes();
	module.exports = function(keyPair, options) {
		var jsEngine = require_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
				}, 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
				}, buffer);
				if (padding === constants.RSA_NO_PADDING) return pkcs1Scheme.pkcs0unpad(res);
				return res;
			}
		};
	};
}) });

//#endregion
export default require_node12();

export { require_node12 };
//# sourceMappingURL=node12.mjs.map