Class: CryptoToolbox::Oracles::UserProfileEncryptionOracle
- Inherits:
-
Object
- Object
- CryptoToolbox::Oracles::UserProfileEncryptionOracle
- Defined in:
- lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb
Instance Method Summary collapse
- #decrypt_profile(ciphertext) ⇒ Object
- #encrypted_profile_for(email) ⇒ Object
-
#initialize(key = SecureRandom.random_bytes(16)) ⇒ UserProfileEncryptionOracle
constructor
A new instance of UserProfileEncryptionOracle.
- #parse_profile(string) ⇒ Object
- #profile_for(email) ⇒ Object
Constructor Details
#initialize(key = SecureRandom.random_bytes(16)) ⇒ UserProfileEncryptionOracle
Returns a new instance of UserProfileEncryptionOracle.
4 5 6 |
# File 'lib/crypto-toolbox/oracles/user_profile_encryption_oracle.rb', line 4 def initialize(key = SecureRandom.random_bytes(16) ) @key = key end |
Instance Method Details
#decrypt_profile(ciphertext) ⇒ Object
21 22 23 24 |
# 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) ⇒ Object
17 18 19 |
# 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) ⇒ Object
13 14 15 |
# 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) ⇒ Object
8 9 10 11 |
# 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 |