如何解决密钥类构造函数NBitcoin错误:EC 密钥的大小应为 32
我正在使用 NBitcoin 库、C# 和 Visual Studio 2019。
想法是创建一个哈希集,将比特币地址解码为字节数组,使用具有此签名的 Key 类构造函数:
Key(byte[] data,int count = -1,bool fCompressedIn = true)
在我的程序中是这样的:
var key = new Key(byteArray,-1,true)
byteArray
是:
byte[] byteArray = Encoders.base58.DecodeData("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe");
最后,我将密钥添加到哈希集中,如下所示:
keys.Add(key);
糟糕的是,编译器卡住了
var key = new Key(byteArray,true)
有错误:
System.ArgumentException: 'EC 密钥的大小应为 32'
我尝试用 Base32 编码:
byte[] byteArray = Encoders.Base32.EncodeData("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe");
无法从字符串转换为字节[]
这个问题困扰我很久了,没有任何解决办法...
代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using NBitcoin;
using NBitcoin.DataEncoders;
namespace MyCoins
{
static class Program
{
static void Main()
{
// Create a HashSet:
var keys = new HashSet<Key>();
// I get the hash of the address:
byte[] byteArray = Encoders.base58.DecodeData("1123UAmo4xoNK2oXWfrrdiCwA6kcUQz9aa");
// I pass the byteArray that I created above
var key = new Key(byteArray,true);
// When I do this,I get the error: 'The size of an EC key should be 32 Parameter name: data'
// Add the key to the HashSet:
keys.Add(key);
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。