コード例 #1
0
        public byte[] GetSharedSecret(byte[] pK)
        {
            BitReader reader = new BitReader(pK);

            byte[] x            = reader.ReadByteArray();
            Point  remotePublic = new Point(
                new BigInteger(x),
                new BigInteger(reader.ReadByteArray(pK.Length - BinaryHelpers.VarIntSize(x.Length) - x.Length))
                );

            return(curve.Multiply(remotePublic, priv).X.ToByteArray()); // Use the x-coordinate as the shared secret
        }
コード例 #2
0
        public static byte[] WithHeader(byte[] message)
        {
            int i = BinaryHelpers.VarIntSize(message.Length);

            byte[] nmsg = new byte[message.Length + i];
            //Support.WriteToArray(nmsg, message.Length, 0);
            BinaryHelpers.WriteVarInt(nmsg, 0, message.Length);
            Array.Copy(message, 0, nmsg, i, message.Length);
            Debug.WriteLine($"Compression:  {nmsg.Length}/{Compress(nmsg, Compression.int16).Length}/{Compress(nmsg, Compression.int32).Length}/{Compress(nmsg, Compression.int64).Length}");
            Debug.WriteLine($"Matches: {Support.ArraysEqual(nmsg, Decompress(Compress(nmsg)))}");
            return(nmsg);
        }