Exemplo n.º 1
0
        public static string EncodeBase58Check(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Calculate checksum (First 4 bytes of Double SHA256 of data)
            byte[] checksum = CalculateChecksum(data);

            // Concatenate data and checksum
            byte[] dataToEncode = ByteArrayUtilities.ConcatenateByteArrays(data, checksum);

            // Encode Base58 and return
            return(EncodeBase58(dataToEncode));
        }
Exemplo n.º 2
0
        public static byte[] DecodeBase58Check(string base58String)
        {
            byte[] bytes = DecodeBase58(base58String);

            byte[] checksum = new byte[4];
            Buffer.BlockCopy(bytes, bytes.Length - checksum.Length, checksum, 0, checksum.Length);

            byte[] data = new byte[bytes.Length - checksum.Length];
            Buffer.BlockCopy(bytes, 0, data, 0, data.Length);

            byte[] calculatedChecksum = CalculateChecksum(data);

            if (!ByteArrayUtilities.CompareByteArrays(checksum, calculatedChecksum))
            {
                throw new Exception("Checksum failure");
            }

            return(data);
        }