Closed skaczor closed 7 years ago
The fix for #70 works only with plain ASCII. This issue happens when the key is generated using the entire range (0-255) for each byte, and encoded as UTF-8.
Example with symmetric-encryption (latest master):
irb(main):002:0> SymmetricEncryption.generate_symmetric_key_files('./examples/symmetric-encryption.yml', 'test')
Generated new Symmetric Key for encryption
Put this value in your configuration file for :key
"\x9BG2\xA8,\x7F`=\xC6*G\x13n\x04\xA6;"
Generated new Initialization Vector for encryption
Put this value in your configuration file for :iv
"s'\x91n\xD0\xE1\x83\x11=\xE1\x9B\xD6\xCE\xB6\xC3:"
dev.yml:
development: &development_defaults
key: "\x9BG2\xA8,\x7F`=\xC6*G\x13n\x04\xA6;"
iv: "s'\x91n\xD0\xE1\x83\x11=\xE1\x9B\xD6\xCE\xB6\xC3:"
cipher: aes-128-cbc
irb(main):006:0> SymmetricEncryption.load!('./examples/dev.yml', 'development')
=> true
irb(main):008:0> SymmetricEncryption.cipher.encrypt("test")
ArgumentError: key must be 16 bytes
from /mnt/data-skaczor/PublishedSources/symmetric-encryption/lib/symmetric_encryption/cipher.rb:512:in `key='
from /mnt/data-skaczor/PublishedSources/symmetric-encryption/lib/symmetric_encryption/cipher.rb:512:in `binary_encrypt'
from /mnt/data-skaczor/PublishedSources/symmetric-encryption/lib/symmetric_encryption/cipher.rb:303:in `encrypt'
Looks like this was fixed in #74.
Please re-open the ticket with further information, or post questions in the gitter support channel if you are still experiencing difficulties.
With Ruby 2.4, as described in #70, key length is validated. If yaml config contains a literal key, such as proposed by
SymmetricEncryption.generate_symmetric_key_files('./examples/symmetric-encryption.yml', 'test')
, getting errorArgumentError: key must be 16 bytes