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
- #encryption_algorithm ⇒ Object
- #hex_decrypt(encoded, key: nil) ⇒ Object
- #hex_encrypt(message, key: nil) ⇒ Object
Instance Method Details
#aes_256_padding ⇒ Object
76 77 78 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 76 def aes_256_padding respond_to?(:cryption_padding) ? cryption_padding : 9 end |
#decrypt(encoded, key: nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 62 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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 48 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 |
#encryption_algorithm ⇒ Object
44 45 46 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 44 def encryption_algorithm 'AES-256-CBC' end |
#hex_decrypt(encoded, key: nil) ⇒ Object
84 85 86 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 84 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
80 81 82 |
# File 'app/models/unidom/common/concerns/aes256_cryptor.rb', line 80 def hex_encrypt(, key: nil) Unidom::Common::Numeration.hex encrypt(, key: key) end |