Encryption#

minecraft.networking.encryption.create_cipher(shared_secret)#

Create a cipher for encrypting and decrypting packets.

Parameters:

shared_secret (bytes) – The shared secret.

Returns:

The cipher to use for encryption and decryption.

Return type:

cryptography.hazmat.primitives.ciphers.Cipher

minecraft.networking.encryption.encrypt_secret_and_token(public_key: bytes, shared_secret: bytes, verify_token: bytes) tuple[bytes, bytes]#

Encrypt the shared secret and verify token using the server’s public key.

Parameters:
  • public_key (bytes) – The server’s public key.

  • shared_secret (bytes) – The shared secret.

  • verify_token (bytes) – The verify token.

Returns:

The encrypted shared secret and verify token.

Return type:

tuple[bytes, bytes]

minecraft.networking.encryption.generate_hash(server_id: str, shared_secret: bytes, public_key: bytes) str#

Generate the hash for the session server.

Parameters:
  • server_id (str) – The server ID.

  • shared_secret (bytes) – The shared secret.

  • public_key (bytes) – The server’s public key.

Returns:

The hash that should be sent to the session server.

Return type:

str

minecraft.networking.encryption.generate_shared_secret()#

Generate a random 16-byte shared secret.

This is just a convenience method, and only does os.urandom(16).

Returns:

The random 16-byte shared secret.

Return type:

bytes

minecraft.networking.encryption.minecraft_hexdigest(sha) str#

Convert a SHA1 hash to a Minecraft hexdigest.

Parameters:

sha (hashlib.sha1) – The SHA1 hash to convert.

Returns:

The hexdigest.

Return type:

str

async minecraft.networking.encryption.process_encryption_request(packet: EncryptionRequest, connection: Connection)#

Processes an encryption request packet.

Parameters:
  • packet – The packet to process.

  • connection – The connection that the packet was recieved on.

Returns:

A dictionary containing shared_secret, encrypted_shared_secret, and encrypted_verify_token.

Return type:

dict[str, bytes]