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

ArgumentError (key must be 32 bytes or longer) in Rails 6 #369

Open
arvindmehra opened this issue May 9, 2020 · 3 comments
Open

ArgumentError (key must be 32 bytes or longer) in Rails 6 #369

arvindmehra opened this issue May 9, 2020 · 3 comments

Comments

@arvindmehra
Copy link

I was using attr_encrypted (1.3.3) in rails 4.1 in User model with following details

attr_encrypted :email, :key => 'some_key'

After upgrading the application to rails 6 attr_encrypted bumped to attr_encrypted (3.1.0) which uses encryptor (~> 3.0.0)

in the encryptor (~> 3.0.0) new validation has been introduced

raise ArgumentError.new("key must be #{cipher.key_len} bytes or longer") if options[:key].bytesize < cipher.key_len

which raises ArgumentError (key must be 32 bytes or longer) exception

How can I keep using the existing :key => 'some_key' in attr_encrypted (3.1.0) version

@arvindmehra arvindmehra changed the title ArgumentError (key must be 32 bytes or longer) ArgumentError (key must be 32 bytes or longer) in Rails 6 May 9, 2020
@valinaga
Copy link

How about use this:

 :key => 'some_key'.bytes[0..31].pack( "c" * 32 )

@peterbajwa
Copy link

It's raising below error

ArgumentError (too few arguments)

@n-at-han-k
Copy link

n-at-han-k commented May 5, 2024

How about use this:

 :key => 'some_key'.bytes[0..31].pack( "c" * 32 )

Works for me on rails 7.1

I changed:

attr_encrypted :email, key: Rails.application.credentials.secret_key_base

to the following:

attr_encrypted :email, key: Rails.application.credentials.secret_key_base.bytes[0..31].pack( "c" * 32 )

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

4 participants