pub struct ServerKeyPair { /* private fields */ }Expand description
An RSA key pair for the Minecraft login handshake.
Generated once at server startup. The public key is sent to clients
in ClientboundHelloPacket; the private key decrypts the client’s
shared secret.
Implementations§
Source§impl ServerKeyPair
impl ServerKeyPair
Sourcepub fn generate() -> Result<Self, CryptoError>
pub fn generate() -> Result<Self, CryptoError>
Generates a new 1024-bit RSA key pair.
§Errors
Returns CryptoError::KeyGeneration if the OS RNG or RSA
generation fails.
Sourcepub fn public_key_der(&self) -> &[u8] ⓘ
pub fn public_key_der(&self) -> &[u8] ⓘ
Returns the DER-encoded public key (X.509 SubjectPublicKeyInfo).
Sourcepub fn public_key(&self) -> &RsaPublicKey
pub fn public_key(&self) -> &RsaPublicKey
Returns a reference to the RSA public key.
Sourcepub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CryptoError>
pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CryptoError>
Decrypts data encrypted with the public key (PKCS#1 v1.5 padding).
Used to decrypt both the shared secret and the verification challenge.
§Errors
Returns CryptoError::Decryption if decryption fails.
Decrypts the client’s shared secret and validates its length.
The shared secret must be exactly 16 bytes (128-bit AES key).
§Errors
Returns CryptoError if decryption fails or the decrypted
secret is not 16 bytes.