Beispiel #1
0
        public static bool VerifyHash(
            byte[] data,
            byte[] signature,
            byte[] publicKey)
        {
            var hash = HmacBlake2b.Compute(data, SignedMessage.HashSizeBits);

            return(Ed25519.Verify(
                       data: hash,
                       signature: signature,
                       publicKey: publicKey));
        }
Beispiel #2
0
        private static SignedMessage SignHash(
            byte[] data,
            byte[] privateKey,
            Func <byte[], byte[], byte[]> signer,
            byte[] watermark = null)
        {
            var dataForSign = data.Copy(offset: 0, count: data.Length);

            if (watermark?.Length > 0)
            {
                var bytesWithWatermark = new byte[dataForSign.Length + watermark.Length];

                Array.Copy(
                    sourceArray: watermark,
                    sourceIndex: 0,
                    destinationArray: bytesWithWatermark,
                    destinationIndex: 0,
                    length: watermark.Length);

                Array.Copy(
                    sourceArray: dataForSign,
                    sourceIndex: 0,
                    destinationArray: bytesWithWatermark,
                    destinationIndex: watermark.Length,
                    length: dataForSign.Length);

                dataForSign = bytesWithWatermark;
            }

            var hash = HmacBlake2b.Compute(dataForSign, SignedMessage.HashSizeBits);

            var signature = signer(hash, privateKey);

            return(new SignedMessage
            {
                Bytes = dataForSign,
                SignedHash = signature,
                EncodedSignature = Base58Check.Encode(signature, Prefix.Edsig),
                SignedBytes = data.ToHexString() + signature.ToHexString()
            });
        }
Beispiel #3
0
        public Keys(byte[] sk, byte[] pk)
        {
            PublicHash = Base58Check.Encode(HmacBlake2b.Compute(pk, PublicKeyHashBitSize), Prefix.Tz1);

            PublicKey  = new SecureString();
            PrivateKey = new SecureString();

            var encodedPk = Base58Check.Encode(pk, Prefix.Edpk);

            foreach (var c in encodedPk)
            {
                PublicKey.AppendChar(c);
            }

            var encodedSk = Base58Check.Encode(sk, Prefix.Edsk);

            foreach (var c in encodedSk)
            {
                PrivateKey.AppendChar(c);
            }

            Array.Clear(pk, 0, pk.Length);
            Array.Clear(sk, 0, sk.Length);
        }
Beispiel #4
0
 public override string AddressFromKey(byte[] publicKey)
 {
     return(Base58Check.Encode(
                payload: HmacBlake2b.Compute(publicKey, PkHashSize),
                prefix: Prefix.Tz1));
 }
 public string HashBytes()
 {
     return(Base58Check.Encode(HmacBlake2b.Compute(Bytes, HashSizeBits)));
 }