Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Created May 2, 2023 23:00
Show Gist options
  • Save thomasjslone/a3f4296ac1576c622a4abbe4641e9922 to your computer and use it in GitHub Desktop.
Save thomasjslone/a3f4296ac1576c622a4abbe4641e9922 to your computer and use it in GitHub Desktop.
really not good password object, do not use this for passwords you share with stuff
require 'openssl'
class Password
def initialize(string, seed)
@seed = seed
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
cipher.key = Digest::SHA256.digest(@seed)
@password = cipher.update(string) + cipher.final
end
def verify(pass)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
cipher.key = Digest::SHA256.digest(@seed)
encrypted = cipher.update(pass) + cipher.final
@password == encrypted
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment