Class: Steam::Crypto
- Inherits:
-
Object
- Object
- Steam::Crypto
- Defined in:
- lib/steam/crypto.rb
Overview
Handles Steam AES key encryption and decrptyion of raw packet data.
Constant Summary collapse
- KEY =
The Steam public key
'MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDf7BrWLBBmLBc1OhSwfFkRf53'\ 'T2Ct64+AVzRkeRuh7h3SiGEYxqQMUeYKO6UWiSRKpI2hzic9pobFhRr3Bvr/WARvY'\ 'gdTckPv+T1JzZsuVcNfFjrocejN1oWI0Rrtgt4Bo+hOneoo3S57G9F1fOpn5nsQ66'\ 'WOiu4gZKODnFMBCiQIBEQ=='
Class Method Summary collapse
-
.decrypt(data, key) ⇒ Object
Decrypt a given string with a given key, get the decrypted data back.
-
.encrypt(data, key) ⇒ Object
Encrypt a given string with a given key, get the encrypted data back.
Instance Method Summary collapse
-
#decrypt(io, key) ⇒ :read
Decrypts the given IO stream using the given key.
-
#encrypt(io, key) ⇒ :read
Encrypts the given IO stream using the given key.
-
#generate_key ⇒ Array
Generates a tuple representing the session key, both plain text and encrypted.
-
#session_key_crc(key) ⇒ Integer
Get the 32 bit crc for the given key.
Class Method Details
.decrypt(data, key) ⇒ Object
Decrypt a given string with a given key, get the decrypted data back.
27 28 29 |
# File 'lib/steam/crypto.rb', line 27 def self.decrypt(data, key) new.decrypt(StringIO.new(data), key).string end |
.encrypt(data, key) ⇒ Object
Encrypt a given string with a given key, get the encrypted data back.
19 20 21 |
# File 'lib/steam/crypto.rb', line 19 def self.encrypt(data, key) new.encrypt(StringIO.new(data), key).string end |
Instance Method Details
#decrypt(io, key) ⇒ :read
Decrypts the given IO stream using the given key
75 76 77 78 79 80 81 82 83 |
# File 'lib/steam/crypto.rb', line 75 def decrypt(io, key) iv_cipher = iv_cipher(key, :decrypt) crypted_iv = io.read(16) iv = iv_cipher.update(crypted_iv) + iv_cipher.final cipher = data_cipher(key, iv, :decrypt) StringIO.new(cipher.update(io.read) + cipher.final) end |
#encrypt(io, key) ⇒ :read
Encrypts the given IO stream using the given key
56 57 58 59 60 61 62 63 64 |
# File 'lib/steam/crypto.rb', line 56 def encrypt(io, key) iv = Random.new.bytes(16) iv_cipher = iv_cipher(key, :encrypt) cipher = data_cipher(key, iv, :encrypt) StringIO.new(iv_cipher.update(iv) + iv_cipher.final + cipher.update(io.read) + cipher.final) end |
#generate_key ⇒ Array
Generates a tuple representing the session key, both plain text and encrypted
39 40 41 42 43 44 45 |
# File 'lib/steam/crypto.rb', line 39 def generate_key key = OpenSSL::PKey::RSA.new(Base64.strict_decode64(KEY)) plain = Random.new.bytes(32) padding = OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING [key.public_encrypt(plain, padding), plain] end |
#session_key_crc(key) ⇒ Integer
Get the 32 bit crc for the given key
89 90 91 |
# File 'lib/steam/crypto.rb', line 89 def session_key_crc(key) Zlib.crc32(key) end |