R
R
Roman Mirilaczvili2017-09-16 16:12:14
ruby
Roman Mirilaczvili, 2017-09-16 16:12:14

How to rewrite PHP openssl_decrypt to Ruby?

Dear PHP experts, please help me rewrite this code in Ruby using openssl.

openssl_decrypt($encrypted, "aes-256-cbc", $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv)

$key is the text "abra-cadabra-123", 32 bytes long.
$iv is the text "abra-cadabra-123", 16 bytes long.
At the same time, openssl does not accept key, iv values ​​other than hex.
Are there any peculiarities in the PHP implementation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2017-09-20
@2ord

In my case, besides

cipher = OpenSSL::Cipher::AES256.new(:CBC)
cipher.decrypt
cipher.key = "..."
cipher.iv  = "..."

it was required to add cipher.resetimmediately after processing the next block with cipher.update.

A
Alexander Aksentiev, 2017-09-16
@Sanasol

ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/Open...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question