Class: Spree::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/encryptor.rb

Overview

Spree::Encryptor is a thin wrapper around ActiveSupport::MessageEncryptor.

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Encryptor

Returns a new instance of Encryptor.

Parameters:

  • key (String)

    the 256 bits signature key



7
8
9
# File 'lib/spree/encryptor.rb', line 7

def initialize(key)
  @crypt = ActiveSupport::MessageEncryptor.new(key)
end

Instance Method Details

#decrypt(encrypted_value) ⇒ String

Decrypt an encrypted value

Parameters:

  • encrypted_value (String)

    the value to decrypt

Returns:

  • (String)

    the decrypted value



21
22
23
# File 'lib/spree/encryptor.rb', line 21

def decrypt(encrypted_value)
  @crypt.decrypt_and_verify(encrypted_value)
end

#encrypt(value) ⇒ String

Encrypt a value

Parameters:

  • value (String)

    the value to encrypt

Returns:

  • (String)

    the encrypted value



14
15
16
# File 'lib/spree/encryptor.rb', line 14

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