reidmorrison / symmetric-encryption

Symmetric Encryption for Ruby Projects using OpenSSL

Home Page:https://logger.rocketjob.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error saving :decimal attribute

jersingh opened this issue · comments

Encrypting many fields successfully in a model/table (PostgreSQL) with various types: :string, :boolean, :integer, and :date. I have one field that is :decimal type and it's the only field that fails when updating.

I'm calling some ajax to save individual attributes like this:

object.update_attribute(attr, value)

Stack trace caught in a rescue block when saving the :decimal:

wrong number of arguments (given 1, expected 0)

Here's my rails model symmetric-encryption definition:

attribute :rent_amount, :encrypted, random_iv: false, type: :decimal

I can change the type to :integer or :float and updates without issue. Just cannot save a :decimal.

My environment:

  • Ruby 2.6.3
  • Symmetric Encryption 4.3.0
  • Rails 5.2.3

Any takers?

I've posted on SO if that is a more appropriate place to ask for help.

https://stackoverflow.com/questions/56763756/rocketjob-symmetric-encryption-error-saving-decimal-attribute

Did you change the column to "string" ? each column should be in string format even when other format. May I ask how did you implement the gem? Im trying to implement myself but getting ArgumentError: Unknown type :encrypted for attribute :name, :encrypted, random_iv: false, type: :string and havent not been able to resolve this.

@michaelsalexander83 I do have my column type set to string.

I basically followed instructions here but this is how I set things up. I'm using version 4.3.0:

  • Installed the gem locally on my system:
$ gem install symmetric-encryption
  • Ran the generator just for production. I'm simulating a production environment and only need one key:
$ symmetric-encryption --generate --app-name your_app_name --environments "production"
  • Moved symmetric-encryption.yml generated from command above from ~/config to my Rails config folder. The above command also generates dot kekek files in ~/.symmetric-encryption folder. I left that file there. You may or may not have to edit your symmetric-encryption.yml file to reflect that placement, I can't remember if I had to.

I was then able to encrypt anything I needed to but :decimal fields.

Here's a sample of how I set up one of my models:

if Rails.application.config.encryption_mode # I set this in my environments
  # these work just dandy
  attribute :dob, :encrypted, random_iv: true, type: :date
  attribute :customer_since, :encrypted, random_iv: true, type: :date
  attribute :years_at_previous_residence, :encrypted, random_iv: true, type: :integer

  # fails with: wrong number of arguments (given 1, expected 0)
  # attribute :rent_amount, :encrypted, random_iv: false, type: :decimal
end

Hope this helps!

Just a quick note. No disrespect intended to the contributors, but I'm a little disappointed not one of the nineteen contributors can jump in to help. I understand the open source software process is a volunteer system and the time and effort involved in producing such a quality gem as this is greatly appreciated, but a system as critical as encryption is really important. I may need to use another library if I can't get my issue resolved.

Cheers!

Just a quick note. No disrespect intended to the contributors, but I'm a little disappointed not one of the nineteen contributors can jump in to help. I understand the open source software process is a volunteer system and the time and effort involved in producing such a quality gem as this is greatly appreciated, but a system as critical as encryption is really important. I may need to use another library if I can't get my issue resolved.

Wow, such a typical response from an over entitled late adopter. This gem was written and is maintained by exactly 1 person in his "free" time. All other contributions are from people that instead of abusing the author, took the took the time and contributed by submitting a pull request.

Please use some other gem since you clearly do not appreciate the "free" time I put in to creating and maintaining this open source gem.