class CryptoToolbox::Oracles::UserProfileEncryptionOracle
Public Class Methods
new(key = SecureRandom.random_bytes(16) )
click to toggle source
# File lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb, line 4 def initialize(key = SecureRandom.random_bytes(16) ) @key = key end
Public Instance Methods
decrypt_profile(ciphertext)
click to toggle source
# File lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb, line 21 def decrypt_profile(ciphertext) plaintext = Ciphers::Aes.new.decipher_ecb(@key,ciphertext).to_crypt_buffer.strip_padding.str parse_profile(plaintext) end
encrypted_profile_for(email)
click to toggle source
# File lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb, line 17 def encrypted_profile_for(email) Ciphers::Aes.new.encipher_ecb(@key,profile_for(email)) end
parse_profile(string)
click to toggle source
# File lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb, line 13 def parse_profile(string) string.split("&").each_with_object({}){|pair,hsh| k,v = pair.split("="); hsh[k.to_sym] = v } end
profile_for(email)
click to toggle source
# File lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb, line 8 def profile_for(email) email.gsub!(/[&=]/,"") # sanitize meta chars "email=#{email}&uid=10&role=guest" end