public static DHWrapper BeginDiffieHellman(ref byte[] pubKey, bool initiator = false)
{
var dh = new DHWrapper();
var size = dh.Keysize;
byte[] newPubKey;
if (initiator)
{
newPubKey = new byte[4 + size];
newPubKey[0] = 0x81;
newPubKey[1] = 0x02;
newPubKey[2] = 0x1D;
newPubKey[3] = 0x02;
pubKey = newPubKey;
Buffer.BlockCopy(dh.PublicKey, 0, newPubKey, 4, size);
return dh;
}
var index = pubKey.Length;
newPubKey = new byte[index + 4 + size];
Buffer.BlockCopy(pubKey,0,newPubKey,0,index);
var byte2 = (byte) (KEY_SIZE - size);
if (byte2 > 2)
{
Logger.WARN("Generation DH key with less of 126 bytes!");
byte2 = 2;
}
byte2 = (byte) (2 - byte2);
newPubKey[index++] = 0x81;
newPubKey[index++] = byte2;
newPubKey[index++] = 0x0D;
newPubKey[index++] = 0x02;
Buffer.BlockCopy(dh.PublicKey, 0, newPubKey, index, size);
pubKey = newPubKey;
return dh;
}