jsencrypt icon indicating copy to clipboard operation
jsencrypt copied to clipboard

Support encryption and decryption without padding

Open zhulik opened this issue 8 years ago • 2 comments

I need to implement deterministic RSA encryption on serverside(Ruby) and then decrypt this data on frontend. My ruby code:

require 'openssl'
require 'base64'

KEY_SIZE=2048

message = 'Test message'

if message.length < KEY_SIZE
  message = message + (' ' * (KEY_SIZE / 8 - message.length))
end

key_file = File.read('public.pem')
public_key = OpenSSL::PKey::RSA.new key_file
result = Base64.encode64(public_key.public_encrypt(message, OpenSSL::PKey::RSA::NO_PADDING))
puts result

But, jsencrypt can't decrypt it=( Is there any workarounds?

zhulik avatar Apr 24 '16 20:04 zhulik

@zhulik did you ever figure out a workaround for this?

rfunduk avatar Apr 29 '17 16:04 rfunduk

From what i've read RSA without padding makes it deterministic, but unfortunately insecure. Hashes are preferred. See this excellent SO answer: https://stackoverflow.com/a/47096284

jlippold avatar Mar 11 '24 15:03 jlippold