Module: Encryption
- Included in:
- ClientConnection, PasswordDialog, ServerConnection
- Defined in:
- lib/game_2d/encryption.rb
Instance Method Summary collapse
- #decrypt(data, iv) ⇒ Object
-
#encrypt(data) ⇒ Object
Returns [encrypted, iv].
- #key=(key) ⇒ Object
- #make_cipher ⇒ Object
-
#make_password_hash(password) ⇒ Object
Same sort of thing /etc/passwd uses.
Instance Method Details
#decrypt(data, iv) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/game_2d/encryption.rb', line 21 def decrypt(data, iv) decipher = make_cipher.decrypt decipher.key = @symmetric_key decipher.iv = iv decipher.update(data) + decipher.final end |
#encrypt(data) ⇒ Object
Returns [encrypted, iv]
14 15 16 17 18 19 |
# File 'lib/game_2d/encryption.rb', line 14 def encrypt(data) cipher = make_cipher.encrypt cipher.key = @symmetric_key iv = cipher.random_iv [cipher.update(data) + cipher.final, iv] end |
#key=(key) ⇒ Object
5 6 7 |
# File 'lib/game_2d/encryption.rb', line 5 def key=(key) @symmetric_key = key end |
#make_cipher ⇒ Object
9 10 11 |
# File 'lib/game_2d/encryption.rb', line 9 def make_cipher OpenSSL::Cipher::AES.new(128, :CBC) end |
#make_password_hash(password) ⇒ Object
Same sort of thing /etc/passwd uses. Provides no security against snooping passwords off the wire, but does make it safer to handle the user password file.
32 33 34 |
# File 'lib/game_2d/encryption.rb', line 32 def make_password_hash(password) password.crypt('RB') end |