'How to generate RSA PKCS5 keypair in Javascript?

I need to create a set of RSA keys (public+private) on the client (javascript), send it to the server (Ruby) that uses those keys to encrypt data, which is sent to a mobile device which needs to decrypt using the same generated private key.

I started by implementing the server-side and encrypt using OpenSSL

public_key = OpenSSL::PKey::RSA.new(Base64.decode64(user_public_key))

encrypted_data = public_key.public_encrypt(data)

For decrypting the data on mobile, I had to use PKCS5 padding for the decryption to work, due to OpenSSL using this padding protocol.

Now I want to create the RSA keys on Javascript, but I fail to find a matching library that uses the same RSA PKCS5 protocol.

I found suggestions to use SubtleCrypto but this uses OAEP rather than PKCS5.

Can anyone please suggest which library I can use with JavaScript in order to create a set of RSA keys that match the encryption protocol used by ruby's OpenSSL and the mobile libraries?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source