Module: Encryptor

Extended by:
Encryptor
Included in:
Encryptor
Defined in:
lib/encryptor.rb,
lib/encryptor/string.rb,
lib/encryptor/version.rb

Overview

A simple wrapper for the standard OpenSSL library

Defined Under Namespace

Modules: String, Version

Instance Method Summary collapse

Instance Method Details

#decrypt(*args, &block) ⇒ Object

Decrypts a :value with a specified :key and :iv.

Optionally accepts :salt, :auth_data, :algorithm, :hmac_iterations, and :insecure_mode options.

Example

decrypted_value = Encryptor.decrypt(value: 'some encrypted string', key: 'some secret key', iv: 'some unique value', salt: 'another unique value')
# or
decrypted_value = Encryptor.decrypt('some encrypted string', key: 'some secret key', iv: 'some unique value', salt: 'another unique value')


48
49
50
# File 'lib/encryptor.rb', line 48

def decrypt(*args, &block)
  crypt :decrypt, *args, &block
end

#default_optionsObject

The default options to use when calling the encrypt and decrypt methods

Defaults to { algorithm: ‘aes-256-gcm’,

auth_data: '',
insecure_mode: false,
hmac_iterations: 2000,
v2_gcm_iv: false }

Run ‘openssl list-cipher-commands’ in your terminal to view a list all cipher algorithms that are supported on your platform



18
19
20
21
22
23
24
# File 'lib/encryptor.rb', line 18

def default_options
  @default_options ||= { algorithm: 'aes-256-gcm',
                         auth_data: '',
                         insecure_mode: false,
                         hmac_iterations: 2000,
                         v2_gcm_iv: false }
end

#encrypt(*args, &block) ⇒ Object

Encrypts a :value with a specified :key and :iv.

Optionally accepts :salt, :auth_data, :algorithm, :hmac_iterations, and :insecure_mode options.

Example

encrypted_value = Encryptor.encrypt(value: 'some string to encrypt', key: 'some secret key', iv: 'some unique value', salt: 'another unique value')
# or
encrypted_value = Encryptor.encrypt('some string to encrypt', key: 'some secret key', iv: 'some unique value', salt: 'another unique value')


35
36
37
# File 'lib/encryptor.rb', line 35

def encrypt(*args, &block)
  crypt :encrypt, *args, &block
end