<s> import hashlib , hmac , struct <EOL> from Crypto import Random <EOL> from Crypto . Cipher import PKCS1_OAEP , AES <EOL> from Crypto . Hash import SHA <EOL> from Crypto . PublicKey import RSA <EOL> from Crypto . Signature import PKCS1_v1_5 <EOL> from pysteamkit . steam_base import UniverseKeys <EOL> BS = <NUM_LIT:16> <EOL> pad = lambda s : s + ( BS - len ( s ) % BS ) * chr ( BS - len ( s ) % BS ) <EOL> unpad = lambda s : s [ <NUM_LIT:0> : - ord ( s [ - <NUM_LIT:1> ] ) ] <EOL> class CryptoUtil : <EOL> @ staticmethod <EOL> def create_session_key ( ) : <EOL> random = Random . new ( ) <EOL> return random . read ( <NUM_LIT:32> ) <EOL> @ staticmethod <EOL> def rsa_encrypt ( input ) : <EOL> rsa = RSA . importKey ( UniverseKeys . Public ) <EOL> cipher = PKCS1_OAEP . new ( rsa ) <EOL> return cipher . encrypt ( input ) <EOL> @ staticmethod <EOL> def rsa_verify ( input , signature ) : <EOL> rsa = RSA . importKey ( UniverseKeys . Public ) <EOL> verifier = PKCS1_v1_5 . new ( rsa ) <EOL> h = SHA . new ( ) <EOL> h . update ( input ) <EOL> return verifier . verify ( h , signature ) <EOL> @ staticmethod <EOL> def symmetric_encrypt ( input , key ) : <EOL> random = Random . new ( ) <EOL> iv = random . read ( <NUM_LIT:16> ) <EOL> aes = AES . new ( key , AES . MODE_ECB ) <EOL> crypted_iv = aes . encrypt ( iv ) <EOL> aes = AES . new ( key , AES . MODE_CBC , iv ) <EOL> encrypted = aes . encrypt ( pad ( input ) ) <EOL> return crypted_iv + encrypted <EOL> @ staticmethod <EOL> def symmetric_decrypt ( input , key ) : <EOL> aes = AES . new ( key , AES . MODE_ECB ) <EOL> decrypted_iv = aes . decrypt ( input [ : BS ] ) <EOL> aes = AES . new ( key , AES . MODE_CBC , decrypted_iv ) <EOL> return unpad ( aes . decrypt ( input [ BS : ] ) ) <EOL> @ staticmethod <EOL> def verify_and_decrypt_password ( input , password ) : <EOL> key = hashlib . sha256 ( str ( password ) ) . digest ( ) <EOL> hmacsha = hmac . new ( key , input [ : <NUM_LIT:32> ] , hashlib . sha1 ) <EOL> if hmacsha . digest ( ) != input [ <NUM_LIT:32> : ] : <EOL> return False <EOL> return CryptoUtil . symmetric_decrypt ( input [ : <NUM_LIT:32> ] , key ) </s>
