1

I am encoding a JSON data in Ruby by using RSA-OAEP with SHA256 hashing algorithm but I am not sure how to achieve in Ruby. I found a gem chilkat

I have tried to encode the JSON data using Chilkat getting nil all times. See below code

[28] pry(main)> pubkey = Chilkat::CkPublicKey.new()
=> #<Chilkat::CkPublicKey:0x00007fe3393c54a0 @__swigtype__="_p_CkPublicKey">
[29] pry(main)>

[30] pry(main)> rsa = Chilkat::CkRsa.new()
=> #<Chilkat::CkRsa:0x00007fe339447e00 @__swigtype__="_p_CkRsa">

[31] pry(main)> rsa.put_OaepPadding(true)
=> nil

[32] pry(main)> rsa.put_OaepHash("SHA1")
=> nil

[33] pry(main)> rsa.ImportPublicKeyObj(pubkey)
=> true

[34] pry(main)> rsa.put_EncodingMode("base64")
=> nil
[35] pry(main)>
Ravindra Yadav
  • 35
  • 1
  • 10

1 Answers1

0

Given that you're using a public key to "encode", I think what you really meant is to "encrypt". With public key encryption, the public key is used to encrypt, and the private key is used to decrypt. The opposite is the case for signatures: Use the private key to sign, and the public key to verify.

Here's an example for RSA-OAEP with SHA256

https://www.example-code.com/ruby/rsa_oaep_sha256.asp

Chilkat Software
  • 1,405
  • 1
  • 9
  • 8