reidmorrison / symmetric-encryption

Symmetric Encryption for Ruby Projects using OpenSSL
https://logger.rocketjob.github.io/
Apache License 2.0
475 stars 92 forks source link

Not work with ruby 2.4 #70

Closed taka0125 closed 7 years ago

taka0125 commented 7 years ago

This Sample not work with ruby 2.4.

vendor/bundle/ruby/2.4.0/gems/symmetric-encryption-3.8.3/lib/symmetric_encryption/cipher.rb:468:in `key=': key must be 16 bytes (ArgumentError)

Code is here.

https://github.com/taka0125/symmetric-encryption-ruby2.4

reidmorrison commented 7 years ago

With Ruby 2.4 it now verifies the length of the key to ensure it matches the cipher.

Please change:

SymmetricEncryption.cipher = SymmetricEncryption::Cipher.new(
  cipher_name: 'aes-128-cbc',
  key:         '1234567890ABCDEF1234567890ABCDEF',
  iv:          '1234567890ABCDEF',
  encoding:    :base64strict
)

Truncating the key to:

SymmetricEncryption.cipher = SymmetricEncryption::Cipher.new(
  cipher_name: 'aes-128-cbc',
  key:         '1234567890ABCDEF',
  iv:          '1234567890ABCDEF',
  encoding:    :base64strict
)

Prior to Ruby 2.4 it just truncated the key when it was too long.

The documentation examples use a key that is too long and will be fixed to use the correct length, per the example above.