Sha256: 41799f72e108becf469721ff0d8e386ab62e44bf04066421cc39c59fc31ccd95
Contents?: true
Size: 876 Bytes
Versions: 1
Compression:
Stored size: 876 Bytes
Contents
class AesCore def self.encrypt(message, password) Base64.urlsafe_encode64(encrypt_data(message.to_s.strip, self.key_digest(password), nil, "AES-256-CBC")) end def self.decrypt(message, password) base64_decoded = Base64.urlsafe_decode64(message.to_s.strip) decrypt_data(base64_decoded, self.key_digest(password), nil, "AES-256-CBC") end def self.key_digest(password) OpenSSL::Digest::SHA256.new(password).digest end private def self.decrypt_data(encrypted_data, key, iv, cipher_type) aes = OpenSSL::Cipher.new(cipher_type) aes.decrypt aes.key = key aes.iv = iv if iv != nil aes.update(encrypted_data) + aes.final end def self.encrypt_data(data, key, iv, cipher_type) aes = OpenSSL::Cipher.new(cipher_type) aes.encrypt aes.key = key aes.iv = iv if iv != nil aes.update(data) + aes.final end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aes_tool-0.1.1 | lib/aes_tool/aes_core.rb |