/// <summary>
        ///     Create a RadixAddress from a Elliptic Curve Public Key
        /// </summary>
        /// <param name="magic"></param>
        /// <param name="publicKey"></param>
        public RadixAddress(int magic, ECPublicKey publicKey)
        {
            if (publicKey == null)
            {
                throw new ArgumentNullException(nameof(publicKey));
            }

            if (publicKey.Length() != 33)
            {
                throw new ArgumentException($"publickey must be 33 in lenghth but was : {publicKey.Length()}");
            }

            byte[] addressBytes = new byte[1 + publicKey.Length() + 4];
            // Universe magic byte
            addressBytes[0] = (byte)(magic & 0xff);
            publicKey.CopyPublicKey(addressBytes, 1);

            // Checksum
            byte[] check = RadixHash.Of(addressBytes, 0, publicKey.Length() + 1).ToByteArray();
            Array.Copy(check, 0, addressBytes, publicKey.Length() + 1, 4);

            //_addressBase58 = Base58.ToBase58(addressBytes);
            _addressBase58 = Base58Encoding.Encode(addressBytes);
            _pubKey        = publicKey;
        }
Esempio n. 2
0
        public virtual byte[] CalculateMAC(byte[] salt, byte[] iv, ECPublicKey publicKey, byte[] encrypted)
        {
            var hmac = new HMac(new Sha256Digest());

            hmac.Init(new KeyParameter(salt));
            byte[] result = new byte[hmac.GetMacSize()];

            using (var stream = new MemoryStream())
            {
                stream.Write(iv, 0, iv.Length);
                stream.Write(publicKey.Base64Array, 0, publicKey.Length());
                stream.Write(encrypted, 0, encrypted.Length);

                var msg = stream.ToArray();

                hmac.BlockUpdate(msg, 0, msg.Length);
            }

            hmac.DoFinal(result, 0);

            return(result);
        }