Class: Udongo::Crypt

Inherits:
Object
  • Object
show all
Defined in:
lib/udongo/crypt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret: Rails.configuration.secret_key_base) ⇒ Crypt

Returns a new instance of Crypt.



4
5
6
# File 'lib/udongo/crypt.rb', line 4

def initialize(secret: Rails.configuration.secret_key_base)
  @options = { secret: secret }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/udongo/crypt.rb', line 2

def options
  @options
end

Instance Method Details

#cryptObject



8
9
10
# File 'lib/udongo/crypt.rb', line 8

def crypt
  @crypt ||= ActiveSupport::MessageEncryptor.new(options[:secret])
end

#decrypt(value) ⇒ Object



16
17
18
# File 'lib/udongo/crypt.rb', line 16

def decrypt(value)
  crypt.decrypt_and_verify(value)
end

#encrypt(value) ⇒ Object



12
13
14
# File 'lib/udongo/crypt.rb', line 12

def encrypt(value)
  crypt.encrypt_and_sign(value)
end