Created
May 2, 2023 23:00
-
-
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
This file contains 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' | |
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