Создайте ethereum publi c адрес из личного ключа - PullRequest
0 голосов
/ 15 марта 2020

https://www.freecodecamp.org/news/how-to-create-an-ethereum-wallet-address-from-a-private-key-ae72b0eee27b/

Почему secp256k1 Ellipti c Кривая не работает?

// 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);
}

Выход:

enter image description here

Ожидаемый результат:

enter image description here

...