Class: Gibberish::AES

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/aes_crypt.rb

Defined Under Namespace

Classes: CBC, SJCL

Instance Method Summary collapse

Constructor Details

#initialize(password, opts = {}) ⇒ AES

Returns the AES object

Parameters:

Options Hash (opts):

  • :mode (Symbol) — default: 'gcm'

    the AES mode to use

  • :ks (Symbol) — default: 256

    keystrength

  • :iter (Symbol) — default: 100_000

    number of PBKDF2 iterations to run on the password

  • :max_iter (Symbol) — default: 100_000

    maximum allow iterations, set to prevent DOS attack of someone setting a large 'iter' value in the ciphertext JSON

  • :ts (Symbol) — default: 64

    length of the authentication data hash


16
17
18
# File 'lib/ext/aes_crypt.rb', line 16

def initialize(password, opts={})
  @cipher = SJCL.new(password, opts)
end

Instance Method Details

#decrypt(ciphertext) ⇒ Object

Returns a Plaintext object (essentially a String with an additional 'adata' attribute)

Parameters:


31
32
33
# File 'lib/ext/aes_crypt.rb', line 31

def decrypt(ciphertext)
  @cipher.decrypt(ciphertext)
end

#encrypt(data, authenticated_data = '') ⇒ Object

Returns the ciphertext in the form of a JSON string

Parameters:

  • data (String)
  • authenticated_data (String) (defaults to: '')

    (Won't be encrypted)


24
25
26
# File 'lib/ext/aes_crypt.rb', line 24

def encrypt(data, authenticated_data='')
  @cipher.encrypt(data, authenticated_data)
end