C# Class OpenStory.Cryptography.EndpointCrypto

Represents a base class for cryptographic packet transformation.
Datei anzeigen Open project: shoftee/OpenStory Class Usage Examples

Public Methods

Method Description
Client ( RollingIvFactory factory, byte clientIv, byte serverIv ) : EndpointCrypto

Creates a new instance of the EndpointCrypto class used for client-side cryptography.

Encryption uses the local IV, decryption uses the remote IV. Server's local IV has flipped version, Client's local IV has regular version.

Decrypt ( byte packet ) : void

Decrypts the given packet in-place.

The array will be modified directly.

EncryptAndPack ( byte packetData ) : byte[]

Encrypts a packet, constructs a header for it and packs them into a new array.

The array given as the packetData parameter is transformed in-place.

Server ( RollingIvFactory factory, byte clientIv, byte serverIv ) : EndpointCrypto

Creates a new instance of the EndpointCrypto class used for server-side cryptography.

Encryption uses the local IV, decryption uses the remote IV. Server's local IV has flipped version, Client's local IV has regular version.

TryGetLength ( byte header, int &length ) : bool

Attempts to extract the length of a packet from its header.

When overriding this method in a derived class, do not call the base implementation.

TryUnpackAndDecrypt ( byte rawData, byte &decryptedData ) : bool

Attempts to unpack the packet data from the given array and decrypt it.

This method will return if and only if the header was invalid.

Private Methods

Method Description
ConstructHeader ( int length ) : byte[]

Constructs a packet header and encodes the given length in it.

When overriding this method in a derived class, do not call the base implementation.

EndpointCrypto ( RollingIv encryptor, RollingIv decryptor ) : System

Initializes a new instance of the EndpointCrypto class.

Method Details

Client() public static method

Creates a new instance of the EndpointCrypto class used for client-side cryptography.
Encryption uses the local IV, decryption uses the remote IV. Server's local IV has flipped version, Client's local IV has regular version.
public static Client ( RollingIvFactory factory, byte clientIv, byte serverIv ) : EndpointCrypto
factory RollingIvFactory The instance to use.
clientIv byte The IV for the client.
serverIv byte The IV for the server.
return EndpointCrypto

Decrypt() public method

Decrypts the given packet in-place.
The array will be modified directly.
public Decrypt ( byte packet ) : void
packet byte The data to decrypt.
return void

EncryptAndPack() public method

Encrypts a packet, constructs a header for it and packs them into a new array.
The array given as the packetData parameter is transformed in-place.
/// Thrown if is . ///
public EncryptAndPack ( byte packetData ) : byte[]
packetData byte The packet data to encrypt and pack.
return byte[]

Server() public static method

Creates a new instance of the EndpointCrypto class used for server-side cryptography.
Encryption uses the local IV, decryption uses the remote IV. Server's local IV has flipped version, Client's local IV has regular version.
public static Server ( RollingIvFactory factory, byte clientIv, byte serverIv ) : EndpointCrypto
factory RollingIvFactory The instance to use.
clientIv byte The IV for the client.
serverIv byte The IV for the server.
return EndpointCrypto

TryGetLength() public method

Attempts to extract the length of a packet from its header.
When overriding this method in a derived class, do not call the base implementation.
public TryGetLength ( byte header, int &length ) : bool
header byte The header byte array to process.
length int A variable to hold the result.
return bool

TryUnpackAndDecrypt() public method

Attempts to unpack the packet data from the given array and decrypt it.
This method will return if and only if the header was invalid.
Thrown if is .
public TryUnpackAndDecrypt ( byte rawData, byte &decryptedData ) : bool
rawData byte The raw packet data.
decryptedData byte A reference to hold the decrypted data.
return bool