Class: Decidim::Initiatives::DataEncryptor
- Inherits:
-
Object
- Object
- Decidim::Initiatives::DataEncryptor
- Defined in:
- decidim-initiatives/app/services/decidim/initiatives/data_encryptor.rb
Overview
Service to encrypt and decrypt metadata
Instance Attribute Summary collapse
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #decrypt(encrypted_data) ⇒ Object
- #encrypt(data) ⇒ Object
-
#initialize(args = {}) ⇒ DataEncryptor
constructor
A new instance of DataEncryptor.
Constructor Details
#initialize(args = {}) ⇒ DataEncryptor
Returns a new instance of DataEncryptor.
9 10 11 12 13 14 15 |
# File 'decidim-initiatives/app/services/decidim/initiatives/data_encryptor.rb', line 9 def initialize(args = {}) @secret = args.fetch(:secret) || "default" @key = ActiveSupport::KeyGenerator.new(secret).generate_key( Rails.application.secret_key_base, ActiveSupport::MessageEncryptor.key_len ) @encryptor = ActiveSupport::MessageEncryptor.new(@key) end |
Instance Attribute Details
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
7 8 9 |
# File 'decidim-initiatives/app/services/decidim/initiatives/data_encryptor.rb', line 7 def secret @secret end |
Instance Method Details
#decrypt(encrypted_data) ⇒ Object
21 22 23 |
# File 'decidim-initiatives/app/services/decidim/initiatives/data_encryptor.rb', line 21 def decrypt(encrypted_data) @encryptor.decrypt_and_verify(encrypted_data) end |
#encrypt(data) ⇒ Object
17 18 19 |
# File 'decidim-initiatives/app/services/decidim/initiatives/data_encryptor.rb', line 17 def encrypt(data) @encryptor.encrypt_and_sign(data) end |