private static byte[] Wif2PrivateKey(string wif)
{
byte[] bytes = Base58.Base58ToByteArray(wif);
Byte[] privKeyAnd80 = new byte[bytes.Length - 4];
Buffer.BlockCopy(bytes, 0, privKeyAnd80, 0, privKeyAnd80.Length);
byte[] hash = new byte[4];
using (var sha256 = new SHA256Managed())
Buffer.BlockCopy(
sha256.ComputeHash(sha256.ComputeHash(privKeyAnd80)), 0,
hash, 0, 4);
byte[] checkSum = new byte[4];
Buffer.BlockCopy(bytes, privKeyAnd80.Length, checkSum, 0, 4);
if (checkSum.SequenceEqual(hash) && (privKeyAnd80[0] == 0x80))
{
byte[] result = new byte[privKeyAnd80.Length - 1];
Buffer.BlockCopy(privKeyAnd80, 1, result, 0, result.Length);
return result;
}
return null;
}