Module: ClearanceCrypto::AES256::InstanceMethods

Defined in:
lib/clearance_crypto/aes256.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#key=(value) ⇒ Object (writeonly)

Sets the attribute key

Parameters:

  • the value to set the attribute key to.



10
11
12
# File 'lib/clearance_crypto/aes256.rb', line 10

def key=(value)
  @key = value
end

Instance Method Details

#aes_plainObject



26
27
28
29
30
31
32
# File 'lib/clearance_crypto/aes256.rb', line 26

def aes_plain
    aes.decrypt
    aes.key = @key
    (aes.update(encrypted_password.unpack("m").first) + aes.final)
  rescue OpenSSL::CipherError
    ''
end

#authenticated?(string) ⇒ Boolean

Returns:



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

def authenticated?(string)
    aes.decrypt
    aes.key = @key
    (aes.update(encrypted_password.unpack("m").first) + aes.final) == string
  rescue OpenSSL::CipherError
    false
end

#encrypt(string) ⇒ Object



12
13
14
15
16
# File 'lib/clearance_crypto/aes256.rb', line 12

def encrypt(string)
  aes.encrypt
  aes.key = @key
  [aes.update(string) + aes.final].pack("m").chomp
end