CSharpRTMP.Core.Protocols.Rtmfp.RtmfpUtils.BeginDiffieHellman C# (CSharp) Method

BeginDiffieHellman() public static method

public static BeginDiffieHellman ( byte &pubKey, bool initiator = false ) : DHWrapper
pubKey byte
initiator bool
return CSharpRTMP.Common.DHWrapper
        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;
        }
      

Usage Example

コード例 #1
0
ファイル: Cookie.cs プロジェクト: zhujingcheng/csharprtmp
        public void Run()
        {
            if (DH == null)
            {
                DH = RtmfpUtils.BeginDiffieHellman(ref Nonce);
                return;
            }
            // Compute Diffie-Hellman secret
            SharedSecret = DH.CreateSharedKey(InitiatorKey);
            // Compute Keys
            RtmfpUtils.ComputeAsymetricKeys(SharedSecret, InitiatorNonce, Nonce, out DecryptKey, out EncryptKey);
            var pSession = _handshake?.CreateSession(Value);

            if (pSession != null)
            {
                pSession.Peer.UserState = this;
            }
        }
All Usage Examples Of CSharpRTMP.Core.Protocols.Rtmfp.RtmfpUtils::BeginDiffieHellman