Sha256: d5f7ef521450f429aa03cd20b083c2950670cce6aa973e68fa5247e141b7560f
Contents?: true
Size: 1013 Bytes
Versions: 51
Compression:
Stored size: 1013 Bytes
Contents
require 'openssl' require 'base64' module Rubber module Encryption def cipher_algorithm OpenSSL::Cipher.new("AES-256-CBC") end def cipher_digest OpenSSL::Digest.new("SHA256") end def generate_encrypt_key OpenSSL::Digest.hexdigest('md5', rand.to_s) end def encrypt(payload, secret) cipher = cipher_algorithm cipher.encrypt cipher.pkcs5_keyivgen(cipher_digest.hexdigest(secret)) encrypted_data = cipher.update(payload) + cipher.final encoded_encrypted_data = Base64.encode64(encrypted_data) return encoded_encrypted_data end def decrypt(encoded_encrypted_data, secret) cipher = cipher_algorithm cipher.decrypt cipher.pkcs5_keyivgen(cipher_digest.hexdigest(secret)) encrypted_data = Base64.decode64(encoded_encrypted_data) payload = cipher.update(encrypted_data) + cipher.final return payload end extend self end end
Version data entries
51 entries across 51 versions & 1 rubygems