BitSharper.Base58.DecodeChecked C# (CSharp) 메소드

DecodeChecked() 공개 정적인 메소드

Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data.
If the input is not base 58 or the checksum does not validate.
public static DecodeChecked ( string input ) : byte[]
input string
리턴 byte[]
        public static byte[] DecodeChecked(string input)
        {
            var tmp = Decode(input);
            if (tmp.Length < 4)
                throw new AddressFormatException("Input too short");
            var checksum = new byte[4];
            Array.Copy(tmp, tmp.Length - 4, checksum, 0, 4);
            var bytes = new byte[tmp.Length - 4];
            Array.Copy(tmp, 0, bytes, 0, tmp.Length - 4);
            tmp = Utils.DoubleDigest(bytes);
            var hash = new byte[4];
            Array.Copy(tmp, 0, hash, 0, 4);
            if (!hash.SequenceEqual(checksum))
                throw new AddressFormatException("Checksum does not validate");
            return bytes;
        }

Usage Example

예제 #1
0
        /// <exception cref="AddressFormatException"/>
        protected VersionedChecksummedBytes(string encoded)
        {
            var tmp = Base58.DecodeChecked(encoded);

            Version = tmp[0];
            Bytes   = new byte[tmp.Length - 1];
            Array.Copy(tmp, 1, Bytes, 0, tmp.Length - 1);
        }