Skip to main content

ServerKeyPair

Struct ServerKeyPair 

Source
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

Source

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.

Source

pub fn public_key_der(&self) -> &[u8]

Returns the DER-encoded public key (X.509 SubjectPublicKeyInfo).

Source

pub fn public_key(&self) -> &RsaPublicKey

Returns a reference to the RSA public key.

Source

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.

Source

pub fn decrypt_shared_secret( &self, encrypted_secret: &[u8], ) -> Result<[u8; 16], CryptoError>

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.

Trait Implementations§

Source§

impl Debug for ServerKeyPair

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V