Issue saving non-string fields - Encrypted date test must be a value encrypted using SymmetricEncryption.encrypt
jersingh opened this issue · comments
I'm evaluating this gem for a project and have set up some fields on an existing model and running tests in console on a Ruby 2.4.2/Rails 5.0.6, SE 4.0.0 system in development mode. I'm having issues saving/encrypting non-string fields. Example on date field follows.
symmetric-encryption.yml:
development: &development_defaults
key: 1234567890ABCDEF
iv: 1234567890ABCDEF
cipher_name: aes-128-cbc
encoding: :base64strict
model:
attr_encrypted :date_test, random_iv: true, type: :date
validates :encrypted_date_test, symmetric_encryption: true
rails console:
2.4.2 (main):0 > loan = Loan.new
=> #<Loan:0x00007f02646a0578
id: nil,
amount: 0.0,
.
.
.
encrypted_date_test: nil>
2.4.2 (main):0 > loan.date_test = Date.parse("Nov 11 2017")
=> Sat, 11 Nov 2017
2.4.2 (main):0 > loan.save
(0.2ms) BEGIN
Validation failed #<Loan id: nil, amount: 0.0,...,encrypted_date_test: nil>
=> Encrypted date test must be a value encrypted using SymmetricEncryption.encrypt
(0.3ms) ROLLBACK
=> false
I tried encrypting the return on the Date.parse method using SymmetricEncryption.encrypt and then setting loan.date to that but also failed.
String fields work fine. I'm sure I've miss-configured something. Help is much appreciated.
Sorry, I realized all encrypted fields must be of string type. Seems fairly obvious now. Comments in the mock User model here explain this.