本文整理汇总了C#中Network.GetVersionBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Network.GetVersionBytes方法的具体用法?C# Network.GetVersionBytes怎么用?C# Network.GetVersionBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network.GetVersionBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateWif
private static string GenerateWif(Key key, string password, Network network)
{
var vch = key.ToBytes();
//Compute the Bitcoin address (ASCII),
var addressBytes = Encoders.ASCII.DecodeData(key.PubKey.GetAddress(network).ToWif());
// and take the first four bytes of SHA256(SHA256()) of it. Let's call this "addresshash".
var addresshash = Hashes.Hash256(addressBytes).ToBytes().SafeSubarray(0, 4);
var derived = SCrypt.BitcoinComputeDerivedKey(Encoding.UTF8.GetBytes(password), addresshash);
var encrypted = EncryptKey(vch, derived);
var version = network.GetVersionBytes(Base58Type.ENCRYPTED_SECRET_KEY_NO_EC);
byte flagByte = 0;
flagByte |= 0x0C0;
flagByte |= (key.IsCompressed ? (byte)0x20 : (byte)0x00);
var bytes = version
.Concat(new[] { flagByte })
.Concat(addresshash)
.Concat(encrypted).ToArray();
return Encoders.Base58Check.EncodeData(bytes);
}
示例2: GetWrappedBase58
public static string GetWrappedBase58(string base58, Network network)
{
var coloredVersion = network.GetVersionBytes(Base58Type.COLORED_ADDRESS);
var inner = Encoders.Base58Check.DecodeData(base58);
inner = inner.Skip(coloredVersion.Length).ToArray();
return Encoders.Base58Check.EncodeData(inner);
}
示例3: GenerateWif
private static string GenerateWif(string passphrase, Network network, LotSequence lotsequence, byte[] ownersalt)
{
bool hasLotSequence = lotsequence != null;
//ownersalt is 8 random bytes
ownersalt = ownersalt ?? RandomUtils.GetBytes(8);
var ownerEntropy = ownersalt;
if(hasLotSequence)
{
ownersalt = ownersalt.Take(4).ToArray();
ownerEntropy = ownersalt.Concat(lotsequence.ToBytes()).ToArray();
}
var prefactor = SCrypt.BitcoinComputeDerivedKey(Encoding.UTF8.GetBytes(passphrase), ownersalt, 32);
var passfactor = prefactor;
if(hasLotSequence)
{
passfactor = Hashes.Hash256(prefactor.Concat(ownerEntropy).ToArray()).ToBytes();
}
var passpoint = new Key(passfactor, fCompressedIn: true).PubKey.ToBytes();
var bytes =
network.GetVersionBytes(Base58Type.PASSPHRASE_CODE)
.Concat(new[] { hasLotSequence ? (byte)0x51 : (byte)0x53 })
.Concat(ownerEntropy)
.Concat(passpoint)
.ToArray();
return Encoders.Base58Check.EncodeData(bytes);
}
示例4: Create
public static BitcoinEncryptedSecret Create(string wif, Network network)
{
var raw = Encoders.Base58Check.DecodeData(wif);
var version = raw.Take(2).ToArray();
if(Utils.ArrayEqual(version, network.GetVersionBytes(Base58Type.ENCRYPTED_SECRET_KEY_NO_EC)))
return new BitcoinEncryptedSecretNoEC(wif, network);
if(Utils.ArrayEqual(version, network.GetVersionBytes(Base58Type.ENCRYPTED_SECRET_KEY_EC)))
return new BitcoinEncryptedSecretEC(wif, network);
throw new FormatException("Invalid encrypted secret");
}