ssg / SimpleBase

.NET library for encoding/decoding Base16, Base32, Base58 and Base85.
Apache License 2.0
147 stars 21 forks source link

Decode of encoded Sha256 hashes (32 bytes) results in 31 bytes long hash #10

Closed marian-gheorghe closed 5 years ago

marian-gheorghe commented 5 years ago

Simple C# code to reproduce the issue

class Program
{
    public static byte[] Sha256(byte[] data)
    {
        var sha256 = SHA256.Create();
        return sha256.ComputeHash(data);
    }

    static void Main(string[] args)
    {
        byte[] bytes = { 0, 0, 0, 0, 0, 0, 20, 131, 0, 0, 1, 61, 2 };
        var hashBytes = Sha256(bytes);
        var encoded = Base58.Bitcoin.Encode(hashBytes);
        var decoded = Base58.Bitcoin.Decode(encoded);

        if (hashBytes.Length != decoded.Length)
            Console.WriteLine("Failed : Expected {0} computed {1}", hashBytes.Length, decoded.Length);
    }
}
ssg commented 5 years ago

I fixed this in 818175a5fa5fbdb9b19d472d983f02d1ad3ac268 which was included in 1.8.0 release. Thanks!