I am 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 ciphertext in the API request, and at the end of the API I get the following error (after reading the API logs):
javax.crypto.BadPaddingException: Decryption error
Now I am faced with numerous questions in Stackoverflow, but given my Ruby code, I am mistaken that the ciphertext cannot be decrypted at the end of the API. Obviously, Java is used at the end of the API.
I am completely zero when it comes to encryption, but through encryption and decryption in Ruby I made sure that the implementation is correct in Ruby. The problem occurs when text encrypted through the Ruby language is decrypted through Java at the end of the API.
Java Ruby, . , , ruby openssl Java. Java , , :
, , , Java. , , , BadPadding.
, base64 , Java. , . base64 , . BadPaddingException. , Java Base64URL Base64? Java base64url, , . , , base64, , base64url encoder ( , ).
openJdk, BadPaddingException " (un) ". , : , , , - , . , , , - - .
'PKCS1 padding 11 .
, 11
For 1024-bit RSA keys, the encryption size is usually 117 and the decryption buffer size is 128.
Source: https://habr.com/ru/post/1688911/More articles:How to get window id from header by swift3 - swift3Cannot activate restriction using anchors - iosHow to add JAR dependency in java azure functions - mavenSQL Server (2014) Odd behavior from options in IN (list) - sql-serverСоединительные элементы со строкой Python в списке - pythonDifference between base and url base64 coding in Java 8 - javaHow to transfer my Google App Engine project to Compute Engine completely? - pythonНастроить макет текстового ввода - androidRounded editext background rectangle with a tooltip in the upper left corner of the background - androidFailed to create node_modules folder on host and connect host folder to container - dockerAll Articles