I am using openssl library for RSA encryption and decryption. my ruby version 2.6.10 and rails version is 5.2.8.1
version of openssl is
OpenSSL::VERSION => 2.1.2
OpenSSL::OPENSSL_VERSION => "OpenSSL 1.1.1f 31 Mar 2020"
Below is my code.
private_key = OpenSSL::PKey::RSA.new(private_key)
private_key.private_decrypt("testing", OpenSSL::PKey::RSA::PKCS1_PADDING)
Output of above code is below
"\xC5NxBFNGx02xEBxF7cxADxB7x04W3xF9xFDxCEhx99AxCF7vX2hx99xA9x18xE0x16xA6xA9xEF?)x0ExCEx10xE9JGxD0xA2x91TYxCBxA9~xD5xqlxF5acxC5)|x1F{xD0xC6om0xACxB3xD7xEDRKxC15xAFx1CxEAb4x8E8xC6xA4WxB5RxE4G=xE4xAFxCExxEBx99`ZxEDhxFDxE7xB6x0E|4xDEJYxD1x0ExC2&xD2xCDvlx89 xE7x11xAA/xDAx00xE0Bx0FxF4x8Dx98x96DxD6vxE8xF5xAFxF0!TxEDx8Eg;xF6xF4xBD1x18;o^xD0/x80x10x84!dar"x17xD3rx14yxA6x82Gb&xEFx85xBF'x13Ex83Sx0Fx83xC5x83x9APxC6JsxA0dxFD*xB4*^xAAxE8x0ExB2.xD4xF8xC2x90x16t5xF1<x93KxB4"
But when i am executing above same code in below environment same code is giving me an error OpenSSL::PKey::RSAError: padding check failed
ruby 1.9.3
rails 3.2.21
OpenSSL::VERSION => "1.1.0"
OpenSSL::OPENSSL_VERSION => "OpenSSL 1.0.2g 1 Mar 2016"
What i don’t understand is why openssl version OpenSSL 1.1.1f 31 Mar 2020 is decrypting unencrypted data in this case “testing” ? why i am not getting OpenSSL::PKey::RSAError: padding check failed error ? is anything changed between openssl version “OpenSSL 1.0.2g 1 Mar 2016” and “OpenSSL 1.1.1f 31 Mar 2020” ?