[英]Generate Bitcoin public/private key from Guid C#
I have a randomly generated 128 bit guid (cryptographically secure).我有一个随机生成的 128 位 guid(加密安全)。 How can I use this as a seed to generate a public and private key for Bitcoin, using C#?
如何使用 C# 将其用作种子来生成比特币的公钥和私钥? By seed, I mean that every time I use the same guid as input, it should result in the same public\/private keys.
通过种子,我的意思是每次我使用相同的 guid 作为输入时,它应该产生相同的公钥\/私钥。
I have looked at NBitcoin, but don't understand how to pull it off.我看过 NBitcoin,但不明白如何实现它。
You can directly create 32 random bytes to be your private key.您可以直接创建 32 个随机字节作为您的私钥。 Example below.
下面举例。 But it is VERY important: these 32 bytes must be from cryptographically-secure pseudorandom generator.
但它非常重要:这 32 个字节必须来自加密安全的伪随机生成器。 For example, if you use C# built-in Random class, anyone will be able to restore your private keys with regular computer.
例如,如果您使用 C# 内置的 Random 类,任何人都可以使用普通计算机恢复您的私钥。 You need to be very careful if you plan to use this in real bitcoin network.
如果你打算在真实的比特币网络中使用它,你需要非常小心。 I am not sure if Guid generation is cryptographically-secure.
我不确定 Guid 生成是否加密安全。
static void Main(string[] args)
{
byte[] GetRawKey()
{
// private key=1 in this example
byte[] data = new byte[32];
data[^1] = 1;
return data;
}
var key = new Key(GetRawKey()); // private key
var pair = key.CreateKeyPair(); // key pair (pub+priv keys)
var addrP2pkh = key.GetAddress(ScriptPubKeyType.Legacy, Network.Main); // P2PKH address
var addrP2sh = key.GetAddress(ScriptPubKeyType.SegwitP2SH, Network.Main); // Segwit P2SH address
Console.WriteLine(addrP2pkh.ToString());
Console.WriteLine(addrP2sh.ToString());
}
您可以在此处找到如何从 Private 计算公钥的信息https:\/\/bitcoin-math.000webhostapp.com<\/a>此外,您可以在没有 NBitcoin 类密钥的 C# 上找到加倍、加法和标量乘法函数,仅使用 BigInteger。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.