This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'base64' | |
# AES256 encryption | |
def aes_encrypt(text, key) | |
cipher = get_cipher.tap { _1.encrypt; _1.key = key } | |
iv = cipher.random_iv # 16 bytes | |
cipher_text = cipher.update(text) + cipher.final | |
# *ensure there is no newline char in the encoded text | |
Base64.strict_encode64(iv + cipher_text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
class Practice | |
def initialize | |
@fname = 'data.txt' | |
# predefined key for the demo (32-byte) | |
@key = "12345678901234567890123456789012" | |
# prepage libraries in bg for faster start | |
@libs_loading_thr = Thread.new do | |
require 'openssl' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'sqlite3' | |
require 'bcrypt' | |
# initialize SQLite database | |
DB = SQLite3::Database.new 'users.db' | |
DB.results_as_hash = true | |
# create users table if needed | |
DB.execute <<-SQL |
OlderNewer