public static byte[] GetPrivateKeyFromImport(string wif, int len) { // Convert it to a byte string using Base58Check encoding var decoded = Base58Check.DecodePlain(wif); // Drop the last 4 checksum bytes from the byte string // Drop the first byte (it should be 0x80) // If the private key corresponded to a compressed public key, also drop the last byte (it should be 0x01) var privateKey = decoded.Take(decoded.Length - 4).Skip(1).Take(len).ToArray(); return(privateKey); }
public void TestEncodeDecode() { // Without checksum string encoded = Base58Check.EncodePlain(testValue); Assert.AreEqual(encoded, testValueEncoded); byte[] decoded = Base58Check.DecodePlain(encoded); CollectionAssert.AreEqual(decoded, testValue); // With checksum encoded = Base58Check.Encode(testValue); Assert.AreEqual(encoded, testValueWithChecksumEncoded); decoded = Base58Check.Decode(encoded); CollectionAssert.AreEqual(decoded, testValue); }