Skip to content

Instantly share code, notes, and snippets.

View AELSchauer's full-sized avatar

Ashley Schauer AELSchauer

  • Buoy Software
  • Denver, CO
View GitHub Profile
@wteuber
wteuber / encrypt_decrypt.rb
Last active February 2, 2026 15:13
Basic encrypt and decrypt Strings in Ruby with deterministic salt or IV, generate and store random salt and IV in production
require 'openssl'
class String
CIPHER_NAME = 'aes-256-cbc'.freeze
PBKDF_ITER = 200_000
KEY_LEN = 32 # 256 bits
SALT_CONST = "fixed-global-salt-v1".freeze
IV_SALT_CONST = "fixed-iv-salt-v1".freeze
def encrypt(password)