示例#1
0
        public byte[] ToBytes(EcPointFormat format = EcPointFormat.Mixed, int l = -1)
        {
            if (Inf)
            {
                throw new InvalidOperationException();
            }
            var xb = X.ToByteArrayUBe(l);

            if (format == EcPointFormat.Compressed)
            {
                var r = new byte[xb.Length + 1];
                xb.CopyTo(r, 1);
                r[0] = Y.IsEven ? (byte)2 : (byte)3;
                return(r);
            }
            else
            {
                var yb = Y.ToByteArrayUBe(l);
                if (l == -1)
                {
                    return(ToBytes(format, Math.Max(xb.Length, yb.Length)));
                }

                var r = new byte[l * 2 + 1];
                r[0] = format == EcPointFormat.Uncompressed ? (byte)4 : Y.IsEven ? (byte)6 : (byte)7;
                xb.CopyTo(r, 1);
                yb.CopyTo(r, l + 1);
                return(r);
            }
        }
示例#2
0
 public byte[] ToBytes(AsymmetricAlgorithm a, EcPointFormat format = EcPointFormat.Compressed)
 => ToBytes(format, (a.KeySize + 7) / 8);