2

I want encrypt message on the site with user's key and decrypt it on the server side, but decryption doesn't work.

crypto-js(coffe js):

$(document).on 'click', '.subclick', ->
  text = $('#myform_text').val()
  pass = $('#myform_passphrase').val()
  days = $('#store_days').val()
  encrypted = CryptoJS.AES.encrypt(text, pass)
  $.post '/otprecs',
    text: encrypted.toString(CryptoJS.enc.utf8);
    store_days: days
  return

ruby decrypt function:

 def decrypt_text(passphrase, text)
    encrypted = Base64.decode64(text)
    cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
    cipher.decrypt
    cipher.key = Digest::SHA256.digest(passphrase.chomp)
    text = cipher.update(encrypted)
    text << cipher.final
    puts text
  end

Do you have any ideas?

alterpub
  • 401
  • 1
  • 4
  • 15
  • You have to recreate EVPkdf from CryptoJS in ruby. [Here](http://stackoverflow.com/a/27250883/1816580) is a Java version or use the [EVP_BytesToKey](https://www.openssl.org/docs/crypto/EVP_BytesToKey.html) function. – Artjom B. Feb 01 '15 at 22:57
  • Any luck so far, I need the exact same solution – przbadu May 08 '18 at 10:33

0 Answers0