Пример #1
0
        /// <summary>
        /// 使用自己的私钥与对方公钥进行密钥交换(私钥A×公钥B = 私钥B×公钥A)
        /// </summary>
        /// <param name="privateKey"></param>
        /// <param name="publicKey"></param>
        /// <returns></returns>
        unsafe public static EncryptionKey CreateEncryptionKey(ReadOnlySpan <byte> privateKey, PublicKey publicKey)
        {
            if (privateKey.Length != 32)
            {
                throw new InvalidPrivateKeyException("私钥长度必须是32字节");
            }
            var k = new U256(privateKey, bigEndian: true);

            if (k.IsZero || k >= ModN.N)
            {
                throw new InvalidPrivateKeyException();
            }

            var p = ModP.Mul(publicKey.ToPoint(), k);

            Clear(&k);
            return(new EncryptionKey(ModP.ToU256(p.X), ModP.ToU256(p.Y)));
        }
Пример #2
0
 public static Task <bool> VerifyAsync(PublicKey publicKey, ReadOnlyMemory <byte> message, Signature signature)
 {
     return(Task.Run(() => Verify(publicKey, message.Span, signature)));
 }