2

I'm trying to encrypt two columns on my User model in Ruby on Rails. I have already successfully encrypted 6 other columns on a different table but this time I am getting the error must specify an iv only on the User table.

I am using the devise gem for authentication.

Here is my original migration to add the columns:

class AddPushNotificationColumnsToUser < ActiveRecord::Migration[5.1]
  def change
    add_column :users, :endpoint, :string
    add_column :users, :expiration_time, :string
    add_column :users, :encrypted_p256dh, :string
    add_column :users, :encrypted_auth, :string

    add_column :users, :encrypted_p256dh_iv, :string
    add_column :users, :encrypted_auth_iv, :string
  end
end

My Model:

attr_encrypted :p256dh, key: Rails.application.secrets.db_encryption_key
attr_encrypted :auth, key: Rails.application.secrets.db_encryption_key

When I call User.first.p256dh or User.first.auth I get the error:must specify an iv

Any help would be appreciated.

Cannon Moyer
  • 3,014
  • 3
  • 31
  • 75
  • 1
    What version of `attr_encrypted` are you using? It looks like there might be some issues with newer versions - https://github.com/attr-encrypted/attr_encrypted/issues/306 – supremebeing7 Jul 19 '18 at 15:30
  • Using 3.1 which is version with issues. I'm going to downgrade and give it another try. – Cannon Moyer Jul 19 '18 at 15:34
  • @supremebeing7 I've tried the downgrade and I'm still getting the same error. – Cannon Moyer Jul 19 '18 at 15:46
  • You might want to look an my answer [here](https://stackoverflow.com/questions/51684140/must-specify-an-iv-attr-encrypted-how-to-check-login-and-password/52415672#52415672) – Peter Bloom Sep 20 '18 at 00:02

0 Answers0