Module: Unidom::Common::Concerns::Aes256Cryptor::ClassMethods
- Defined in:
- app/models/unidom/common/concerns/aes256_cryptor.rb
Instance Method Summary collapse
- #aes_256_padding ⇒ Object
- #decrypt(encoded, key: nil) ⇒ Object
- #encrypt(message, key: nil) ⇒ Object
- #hex_decrypt(encoded, key: nil) ⇒ Object
- #hex_encrypt(message, key: nil) ⇒ Object
Instance Method Details
#aes_256_padding ⇒ Object
59 60 61 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 59 def aes_256_padding respond_to?(:cryption_padding) ? cryption_padding : 9 end |
#decrypt(encoded, key: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 45 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
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 31 def encrypt(, key: nil) raise ArgumentError.new('The message argument is required.') if .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()+cipher.final end |
#hex_decrypt(encoded, key: nil) ⇒ Object
67 68 69 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 67 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
63 64 65 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 63 def hex_encrypt(, key: nil) Unidom::Common::Numeration.hex encrypt(, key: key) end |