Module: AppyantraAdmin::Crypto
- Defined in:
- lib/appyantra_admin/crypto.rb
Constant Summary collapse
- SHA256 =
Digest::SHA2.new(256)
- AES =
OpenSSL::Cipher::Cipher.new("AES-256-CBC")
- IV =
"I" * 32
- KEY =
SHA256.digest(self.key_phrase)
- @@key_phrase =
'Some random phrase'
Class Method Summary collapse
-
.decrypt(encrypted_data) ⇒ Object
Decrypts the encrypted data.
- .decrypt_from_base64(data) ⇒ Object
-
.encrypt(payload) ⇒ Object
Encrypts the payload.
- .encrypt_to_base64(data) ⇒ Object
Class Method Details
.decrypt(encrypted_data) ⇒ Object
Decrypts the encrypted data
26 27 28 29 30 31 |
# File 'lib/appyantra_admin/crypto.rb', line 26 def self.decrypt(encrypted_data) AES.decrypt AES.key = KEY AES.iv = IV AES.update(encrypted_data) + AES.final end |
.decrypt_from_base64(data) ⇒ Object
38 39 40 41 |
# File 'lib/appyantra_admin/crypto.rb', line 38 def self.decrypt_from_base64(data) return unless data decrypt(Base64.decode64(data)) end |
.encrypt(payload) ⇒ Object
Encrypts the payload
18 19 20 21 22 23 |
# File 'lib/appyantra_admin/crypto.rb', line 18 def self.encrypt(payload) AES.encrypt AES.key = KEY AES.iv = IV AES.update(payload) + AES.final end |
.encrypt_to_base64(data) ⇒ Object
33 34 35 36 |
# File 'lib/appyantra_admin/crypto.rb', line 33 def self.encrypt_to_base64(data) return unless data Base64.encode64(encrypt(data)) end |