Method: Nexus::Cipher#initialize

Defined in:
lib/nexus/cipher.rb

#initialize(pass, token = nil) ⇒ Cipher

Returns a new instance of Cipher.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nexus/cipher.rb', line 7

def initialize(pass, token = nil)
  @token = Base64.strict_decode64(token) if token
  @token ||= OpenSSL::Random.random_bytes(32)

  iter = 20_000
  key_len = 32
  @key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass,
                                         @token,
                                         iter,
                                         key_len)
end