X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FAddressTools.cs;h=b7409874594037b0c91f97a892a90ce60f61af3b;hb=1dcac5faa2b1477034f82466ffb16170fa2e9bb6;hp=1bf7e2ab4b22b2fa4c49e1b107631c00140596b8;hpb=4426ee1dc8ae6733d46b5413d3bce28333792d22;p=NovacoinLibrary.git diff --git a/Novacoin/AddressTools.cs b/Novacoin/AddressTools.cs index 1bf7e2a..b740987 100644 --- a/Novacoin/AddressTools.cs +++ b/Novacoin/AddressTools.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,6 +6,7 @@ using Org.BouncyCastle.Math; namespace Novacoin { + [Serializable] public class Base58Exception : Exception { public Base58Exception() @@ -63,13 +63,11 @@ namespace Novacoin /// /// Byte sequence /// Base58(data+checksum) - public static string Base58EncodeCheck(IEnumerable bytes) + public static string Base58EncodeCheck(byte[] bytes) { - byte[] dataBytes = bytes.ToArray(); - Array.Resize(ref dataBytes, dataBytes.Length + 4); - - byte[] checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray(); - + var dataBytes = new byte[bytes.Length + 4]; + bytes.CopyTo(dataBytes, 0); + var checkSum = CryptoUtils.ComputeHash256(bytes).Take(4).ToArray(); checkSum.CopyTo(dataBytes, dataBytes.Length - 4); // add 4-byte hash check to the end return Base58Encode(dataBytes); @@ -115,22 +113,22 @@ namespace Novacoin return bi; } - public static IEnumerable Base58DecodeCheck(string strBase58Check) + public static byte[] Base58DecodeCheck(string strBase58Check) { - byte[] rawData = Base58Decode(strBase58Check).ToArray(); + var rawData = Base58Decode(strBase58Check).ToArray(); if (rawData.Length < 4) { throw new Base58Exception("Data is too short."); } - byte[] result = new byte[rawData.Length - 4]; - byte[] resultCheckSum = new byte[4]; + var result = new byte[rawData.Length - 4]; + var resultCheckSum = new byte[4]; Array.Copy(rawData, result, result.Length); Array.Copy(rawData, result.Length, resultCheckSum, 0, 4); - byte[] checkSum = Hash256.Compute256(result).hashBytes.Take(4).ToArray(); + var checkSum = CryptoUtils.ComputeHash256(result).Take(4).ToArray(); if (!checkSum.SequenceEqual(resultCheckSum)) {