public EncryptionContext(Connection conn, AES aes) : this(conn) { this.aes = aes; }
void PerformEncryptionHandshakeServer() { rsa = Security.KeyProvider.GetRSA(); // Send Public Modulus and Exponent Connection.WriteRaw(rsa.PublicKey); Connection.WriteRaw(rsa.Exponent); // Receive 64 bytes (padded to RSA key size) containing AES Key and Ivec byte[] answer = new byte[Security.RSA.KeySize]; Connection.GetRaw(answer); byte[] decryptedKeyInfo; try { decryptedKeyInfo = rsa.Decrypt(answer); } catch (CryptographicException) { throw new InvalidHandshakeException(InvalidHandshakeException.HandshakePhase.EncryptionChannelTest); } byte[] aeskey = decryptedKeyInfo.Take(Security.AES.KeySize).ToArray(); byte[] aesivec = decryptedKeyInfo.Skip(Security.AES.KeySize).Take(Security.AES.BlockSize).ToArray(); aes = new Security.AES(aeskey, aesivec); }
public EncryptionContext(Connection conn, byte[] aesKey, byte[] aesIvec) : this(conn) { aes = new Security.AES(aesKey, aesIvec); }
void PerformEncryptionHandshakeClient() { byte[] pubkey = new byte[Security.RSA.KeySize]; byte[] exponent = new byte[Security.RSA.ExponentSize]; Connection.GetRaw(pubkey); Connection.GetRaw(exponent); rsa = new Security.RSA(pubkey, exponent); aes = Security.KeyProvider.GetAES(); byte[] aesAndIV = new byte[Security.AES.KeySize + Security.AES.BlockSize]; Array.Copy(aes.aesKey, 0, aesAndIV, 0, Security.AES.KeySize); Array.Copy(aes.aesIV, 0, aesAndIV, Security.AES.KeySize, Security.AES.BlockSize); Connection.WriteRaw(rsa.Encrypt(aesAndIV)); }