Skip to content

Instantly share code, notes, and snippets.

View Inversion-des's full-sized avatar
:octocat:
Developing

Yuriy Babak Inversion-des

:octocat:
Developing
View GitHub Profile
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)
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'
@Inversion-des
Inversion-des / hashed_password_demo.rb
Created December 17, 2024 16:22
Store hashed passwords in DB
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