# Is there exists a working shards for generate ECDSA key pairs, generate public key from private key

**URL:** <https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765>\
**Category:** Help & Support\
**Created:** [July 10, 2022, 4:55pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765 "2022-07-10T16:55:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [July 10, 2022, 4:55pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/1 "2022-07-10T16:55:23Z")

</div>

What i means is a shard like this: [GitHub - Axentro/crystal-ecdsa: C bindings for OpenSSL ECDSA](https://github.com/Axentro/crystal-ecdsa)

But, this shared not works any more, many syntax error, type error.

Thank you.

---

<div class="post-metadata">

**Author:** ![cyangle](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/cyangle/32/1437_2.png) [@cyangle](https://forum.crystal-lang.org/u/cyangle)\
**Post date:** [July 10, 2022, 7:40pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/2 "2022-07-10T19:40:43Z")

</div>

Try this one: [GitHub - spider-gazelle/openssl\_ext: Crystal bindings for OpenSSL RSA](https://github.com/spider-gazelle/openssl_ext)

It should also support ECDSA.

The [jwt](https://github.com/crystal-community/jwt) shard uses it and supports ECDSA tokens.

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [July 11, 2022, 6:52am UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/3 "2022-07-11T06:52:19Z")

</div>

There was an issue with crystal 1.5 using openssl 3.0  
this is resolved now after a `shards update` when using spider-gazelle/openssl\_ext

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [July 11, 2022, 7:55am UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/4 "2022-07-11T07:55:32Z")

</div>

Thank you, i updated to 2.2.0 after `shards update`.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [July 11, 2022, 12:14pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/5 "2022-07-11T12:14:08Z")

</div>

Hi, i guess i misuse something? or there is no way to generate a key pair from a string use openssl\_ext shard?

Following is my code example:

```crystal
      words = env.params.body["mnemonic"].as(String).split(" ")
      m1 = Bip0039::Mnemonic.new words
      key = m1.to_hex # 3c3827b462c004f9f27b44b3c4c3c8db8a25f6f44f4dace4dc69825eb6fb9a02
      p! key
      x = LibCrypto.ec_key_generate_key(key: key) # i want to generate key pair use above string, but no luck.
      p! x
      x

```

When above code run, i get following error:

```auto
 key # => "3c3827b462c004f9f27b44b3c4c3c8db8a25f6f44f4dace4dc69825eb6fb9a02"
 Invalid memory access (signal 11) at address 0x0
 [0x563b85206836] *Exception::CallStack::print_backtrace:Nil +118 in ./magpie-code-admin_cr
 [0x563b851be4ea] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil) +330 in ./magpie-code-admin_cr
 [0x7f29c4f3b304] ?? +139817374692100 in /lib/ld-musl-x86_64.so.1

```

I try use like `esdsa_key_pair = OpenSSL::PKey::EC.new(key: key)`, but not works too, because the key is expected to be a valid private key, but i still not generate it yet.

Thank you.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [July 11, 2022, 12:42pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/6 "2022-07-11T12:42:20Z")

</div>

Hi, @stakach , let me describe my demand, please give me some clue if this is possible when use with `openssl_ext` shards.

1. The first step, i generate some mnemonics, like this: [“measure”, “come”, “cube”, “ostrich”, “wide”, “inspire”, “hello”, “essay”, “ready”, “cute”, “reform”, “sustain”], use can writ e it somewhere, which can be used to restore a hex string like this:

```auto
m1 = Bip0039::Mnemonic.new ["measure", "come", "cube", "ostrich", "wide", "inspire", "hello", "essay", "ready", "cute", "reform", "sustain"]
# => <Bip0039::Mnemonic:0x7f37ca6e4c80 @ent=128, @seed=183297182565288719506055787609377395053>
m1.to_hex
# => "89e5c0d5ce7faaea9ab269b2c6d6d16d"

```

I use [bip39](https://github.com/q9f/bip39.cr) shard for this, it works.

1. Then i need use above hex string, `89e5c0d5ce7faaea9ab269b2c6d6d16d`, or the array of mnemonics, to generate a pair of key, i am blocked on there.

When use go, those code like this:

```nohighlight
import (
	"bytes"
	"crypto/ecdsa"
	"crypto/elliptic"
	"github.com/tyler-smith/go-bip39"
)

	seed, err := bip39.NewSeedWithErrorChecking(mnemonic, "password")
	if err != nil {
		return
	}
	return ecdsa.GenerateKey(elliptic.P256(), bytes.NewBuffer(seed))

```

Thank you.

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [July 11, 2022, 9:58pm UTC](https://forum.crystal-lang.org/t/is-there-exists-a-working-shards-for-generate-ecdsa-key-pairs-generate-public-key-from-private-key/4765/7 "2022-07-11T21:58:50Z")

</div>

not sure, pretty sure Go implements their crypto natively in Go.  
You’ll need to find an OpenSSL example of the same and then we can look at implementing any missing functions
