I'm using the following Ruby code to encrypt a string
require 'openssl'
require 'base64'
public_key = OpenSSL::PKey::RSA.new(File.read('public_key'))
Base64.encode64(public_key.public_encrypt('Some random string that I want to encrypt.'))
I need to pass the encrypted text in a request to the API, and on the API end, I'm getting the following error(read through the API logs):
javax.crypto.BadPaddingException: Decryption error
Now, I have gone through numerous questions over at Stackoverflow, but given my Ruby code, what I'm doing wrong that the encrypted text can't be decrypted on the API end. Obviously, the API end is using Java.
I'm a completely noob when it comes to encryption, but through encrypting and decrypting in Ruby, I have made sure that the implementation is correct in Ruby. The problem arises when the text encrypted through Ruby language gets decrypted through Java on the API end.