Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Ruby 2.5.3, set cipher.key: Exception “key must be 16 bytes" #17

Open
ntloi95 opened this issue Oct 2, 2020 · 1 comment

Comments

@ntloi95
Copy link

ntloi95 commented Oct 2, 2020

   def _setup(action)
        @cipher ||= OpenSSL::Cipher.new(@options[:cipher]) 
        # Toggles encryption mode
        @cipher.send(action)
        @cipher.padding = @options[:padding]
        @cipher.key = @key.unpack('a2'*32).map{|x| x.hex}.pack('c'*32)
  end

When i upgrade to ruby 2.5.3, OpenSSL::Cipher required key length = 16 when @options[:cipher] = 'AES-128-CBC'

@ntloi95
Copy link
Author

ntloi95 commented Oct 2, 2020

@key.unpack('a2'*32).map{|x| x.hex}.pack('c'*32) => "o\xA8\xBB\a#'\xF8\xD0\xE4\v\x85\xFA\xD9\x05\x10\xF9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
we just need the first 16 bytes.

dennissivia added a commit to dennissivia/crypto-toolbox that referenced this issue Mar 11, 2021
Added a monkeypatch as a workaround for the [open issue of the aes
gem](chicks/aes#17).
Once that ticket is closed, the monkeypatch can be removed.
dennissivia added a commit to dennissivia/crypto-toolbox that referenced this issue Mar 11, 2021
The upstream aes gem has an [open issue](chicks/aes#17) regarding
the key size that is set internally. This results in an exception from
OpenSSL.
A PR to fix the issue is already available, but it has not yet been
merged. I decided to add a workaround via a monkey patch for the time
being. This way, we don't need to wait for the upstream merge to fix our
issue.

Once that ticket is closed, the monkeypatch can be removed.
dennissivia added a commit to dennissivia/crypto-toolbox that referenced this issue Mar 11, 2021
The upstream aes gem has an [open issue](chicks/aes#17) regarding
the key size that is set internally. This results in an exception from
OpenSSL.
A PR to fix the issue is already available, but it has not yet been
merged. I decided to add a workaround via a monkey patch for the time
being. This way, we don't need to wait for the upstream merge to fix our
issue.

Once that ticket is closed, the monkeypatch can be removed.
closes #45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant