2 using System.Collections.Generic;
5 using System.Threading.Tasks;
11 public class AddressTools
13 public static string Base58Encode(byte[] bytes)
15 const string strDigits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
16 string strResult = "";
18 int nBytes = bytes.Length;
19 BigInteger arrayToInt = 0;
20 BigInteger encodeSize = strDigits.Length;
22 for (int i = 0; i < nBytes; ++i)
24 arrayToInt = arrayToInt * 256 + bytes[i];
26 while (arrayToInt > 0)
28 int rem = (int)(arrayToInt % encodeSize);
29 arrayToInt /= encodeSize;
30 strResult = strDigits[rem] + strResult;
32 for (int i = 0; i < nBytes && bytes[i] == 0; ++i)
34 strResult = strDigits[0] + strResult;
40 public static string Base58EncodeCheck(byte[] bytes)
42 byte[] dataBytes = new byte[bytes.Length + 4];
43 byte[] checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray();
45 bytes.CopyTo(dataBytes, 0);
46 checkSum.CopyTo(dataBytes, bytes.Length);
48 return Base58Encode(dataBytes);