-
-
Save glides/1a74bdbcd3c3df03246b793fe97f1735 to your computer and use it in GitHub Desktop.
Revisions
-
tmarkovski revised this gist
Feb 26, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ static AsymmetricCipherKeyPair GenerateKeyPair() var publicKey = keyPair.Public as ECPublicKeyParameters; Console.WriteLine($"Private key: {ToHex(privateKey.D.ToByteArrayUnsigned())}"); Console.WriteLine($"Public key: {ToHex(publicKey.Q.GetEncoded())}"); return keyPair; } -
tmarkovski created this gist
Feb 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ using System; using System.Linq; using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Generators; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; namespace Program { class Program { static void Main(string[] args) { GenerateKeyPair(); } static AsymmetricCipherKeyPair GenerateKeyPair() { var curve = ECNamedCurveTable.GetByName("secp256k1"); var domainParams = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H, curve.GetSeed()); var secureRandom = new SecureRandom(); var keyParams = new ECKeyGenerationParameters(domainParams, secureRandom); var generator = new ECKeyPairGenerator("ECDSA"); generator.Init(keyParams); var keyPair = generator.GenerateKeyPair(); var privateKey = keyPair.Private as ECPrivateKeyParameters; var publicKey = keyPair.Public as ECPublicKeyParameters; Console.WriteLine($"Private key: {ToHex(privateKey.D.ToByteArrayUnsigned())}"); Console.WriteLine($"Private key: {ToHex(publicKey.Q.GetEncoded())}"); return keyPair; } static string ToHex(byte[] data) => String.Concat(data.Select(x => x.ToString("x2"))); } }