为什么 secp256k1椭圆曲线失败?
// C#
// I am using HashLib
var ecdsaRaw = Ecdsa(Encoding.ASCII.GetBytes(privKey));
var ecdsaCombined = (BitConverter.ToString(ecdsaRaw.Item1) + BitConverter.ToString(ecdsaRaw.Item2)).Replace("-", "");
var finalResult = HashFactory.Crypto.SHA3.CreateKeccak256().ComputeString(ecdsaCombined, Encoding.ASCII).ToString().Replace("-", "");
var pubKey = "0x" + finalResult.Substring(finalResult.Length - 40, 40);
Console.WriteLine("ECDSA + Keccak256 : " + pubKey);
// Ecdsa Method
public static Tuple<byte[], byte[]> Ecdsa(byte[] privateKey)
{
var privKeyInt = new BigInteger(+1, privateKey);
var parameters = SecNamedCurves.GetByName("secp256k1");
var qa = parameters.G.Multiply(privKeyInt);
var pubKeyX = qa.X.ToBigInteger().ToByteArrayUnsigned();
var pubKeyY = qa.Y.ToBigInteger().ToByteArrayUnsigned();
return Tuple.Create(pubKeyX, pubKeyY);
}
输出:
预期输出: