I have a requirement where I need encrypt a hex string using RSA and an RSA Public Key. I have tried pretty much every single library that I could get my hands on to achieve this, but I either get a "message is to long" error, or the encryption returns a Buffer with only 0 (Zero) values in. I have tried the following libraries:
- node-rsa
- JSEncrypt
- cryptico
- crypto-js
- crypto-browserfy
Here is my scenario:
I obtain the following Hex String:
9a8fddec86ef597006caacd92e74d49acf2720a7e1c17bca994641b1ddd55fc14047b54d8eaebc2a9373e892686ff19c51168aa54ebdf343c09ab2b78d916ad1cd1034f061a0260fd7db6d82f267c3e54ff1e70ad2f6487ba8a58912d720ed36759cf350c9b2cad31012592c2d093b559df3e81fe5dc807238fa707547bfd988
I have to use the following PUBLIC RSA KEY:
-----BEGIN RSA PUBLIC KEY----- MIGWAoGBAMqfGO9sPz+kxaRh/qVKsZQGul7NdG1gonSS3KPXTjtcHTFfexA4MkGA mwKeu9XeTRFgMMxX99WmyaFvNzuxSlCFI/foCkx0TZCFZjpKFHLXryxWrkG1Bl9+ +gKTvTJ4rWk1RvnxYhm3n/Rxo2NoJM/822Oo7YBZ5rmk8NuJU4HLAhAYcJLaZFTO sYU+aRX4RmoF -----END RSA PUBLIC KEY-----
My expected encrypted base64 string should end up as this:
BW8LPswdUtwXD6YD9fjSEAljQEkb47TfD7JoWWkA4brdT4GL4QnnxS0xHntuBm6iDnNtoLZa4gmHiASEHVw/YpoTG5T7oB3okDXhV4DnxUHlC/MZZ/FLRYRYWw+zAPEPKGwP8wVxFqCPWu9rutSbDXl6lPo3cO3Pv1B8+tyET3o=
I used C# and BouncyCastle to achieve this expected output, but for my current use-case, I can only use JavaScript. If anyone can push me in the right direction as to how I will achieve this, or what I might be doing wrong I would really appreciate it.