Class: EncodedToken::Encryptor

Inherits:
Object
  • Object
show all
Includes:
ErrorMessages
Defined in:
lib/encoded_token/encryptor.rb

Overview

EncodedToken::Encryptor

This class is responsible for encryption and decryption.

Constant Summary

Constants included from ErrorMessages

EncodedToken::ErrorMessages::CIPHER_ERRORS, EncodedToken::ErrorMessages::CONFIG_ERRORS, EncodedToken::ErrorMessages::ENCODED_TOKEN_ERRORS, EncodedToken::ErrorMessages::ENCODER_ERRORS, EncodedToken::ErrorMessages::ENCRYPTOR_ERRORS, EncodedToken::ErrorMessages::ERROR_MESSAGES, EncodedToken::ErrorMessages::V1_ENCODER_ERRORS

Instance Method Summary collapse

Instance Method Details

#cipherCipher

Returns the cipher instance.

Returns:

  • (Cipher)

    the cipher instance.



86
87
88
# File 'lib/encoded_token/encryptor.rb', line 86

def cipher
  @cipher
end

#decrypt(encrypted_string) ⇒ String

Decrypts the given encrypted string.

Parameters:

  • encrypted_string (String)

    the string to decrypt.

Returns:

  • (String)

    the decrypted string.



56
57
58
# File 'lib/encoded_token/encryptor.rb', line 56

def decrypt(encrypted_string)
  process_chars(encrypted_string, :decrypt)
end

#encrypt(original_string) ⇒ String

Encrypts the given original string.

Parameters:

  • original_string (String)

    the string to encrypt.

Returns:

  • (String)

    the encrypted string.



43
44
45
# File 'lib/encoded_token/encryptor.rb', line 43

def encrypt(original_string)
  process_chars(original_string, :encrypt)
end

#keyString

Returns the current root key.

Returns:

  • (String)

    the root key.



76
77
78
# File 'lib/encoded_token/encryptor.rb', line 76

def key
  @root_key
end

#paddingInteger

Returns the random padding size for the current root key.

Returns:

  • (Integer)

    the padding size.



66
67
68
# File 'lib/encoded_token/encryptor.rb', line 66

def padding
  @cipher.padding
end

#valid_key?(key) ⇒ Boolean

Validates if the given key is part of the cipher's key list.

Parameters:

  • key (String)

    the key to validate.

Returns:

  • (Boolean)

    true if the key is valid, false otherwise.



30
31
32
# File 'lib/encoded_token/encryptor.rb', line 30

def valid_key?(key)
  @cipher.valid_key?(key)
end