Module: Unidom::Common::Concerns::Aes256Cryptor::ClassMethods

Defined in:
app/models/unidom/common/concerns/aes256_cryptor.rb

Instance Method Summary collapse

Instance Method Details

#aes_256_paddingObject



63
64
65
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 63

def aes_256_padding
  respond_to?(:cryption_padding) ? cryption_padding : 9
end

#decrypt(encoded, key: nil) ⇒ Object

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 49

def decrypt(encoded, key: nil)

  raise ArgumentError.new('The encoded argument is required.') if encoded.blank?
  raise ArgumentError.new('The key argument is required.')     if key.blank?

  cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
  cipher.decrypt
  cipher.padding = aes_256_padding
  cipher.key     = key

  cipher.update(encoded)+cipher.final

end

#encrypt(message, key: nil) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 35

def encrypt(message, key: nil)

  raise ArgumentError.new('The message argument is required.') if message.blank?
  raise ArgumentError.new('The key argument is required.')     if key.blank?

  cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
  cipher.encrypt
  cipher.padding = aes_256_padding
  cipher.key     = key

  cipher.update(message)+cipher.final

end

#encryption_algorithmObject



31
32
33
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 31

def encryption_algorithm
  'AES-256-CBC'
end

#hex_decrypt(encoded, key: nil) ⇒ Object



71
72
73
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 71

def hex_decrypt(encoded, key: nil)
  Unidom::Common::Numeration.hex decrypt(Unidom::Common::Numeration.rev_hex(encoded), key: key)
end

#hex_encrypt(message, key: nil) ⇒ Object



67
68
69
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 67

def hex_encrypt(message, key: nil)
  Unidom::Common::Numeration.hex encrypt(message, key: key)
end