Skip to content

Commit

Permalink
ADD: import/export example
Browse files Browse the repository at this point in the history
  • Loading branch information
go-compile committed Jun 12, 2022
1 parent 249ee22 commit 2bd6976
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,13 @@ The Elliptic and Edward Curve cryptography library built for multi-curve use. Un
- Brainpool P512r1
- Brainpool P512t1

More to come...

# Todo

- Maybe RSA
- secp256k1
- saltpack
- AES CBC
- Encrypt private key option
- Convert keys to SSH keys
- Universal ParseKey() for EC and Ed keys

# Encrypt (ECIES)

Expand Down
40 changes: 40 additions & 0 deletions examples/import/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"crypto/sha1"
"fmt"

"github.com/go-compile/rome/parse"
)

func main() {
fmt.Println("P192r1 Private:")
parsePrivate([]byte(`-----BEGIN EC PRIVATE KEY-----
MF4CAQEEGIGv8cxcdkitRLKR8TQf2SGOoFqzO8Hs4KAJBgcrhkjOPQEDoTQDMgAE
jBSOPviPICiS3A8oRgjYfkA3WMUCJvGclKooR+REWIBCvTEwaQP7DSTooC5z4BdB
-----END EC PRIVATE KEY-----`))

fmt.Println("P192r1 Public:")
parsePublic([]byte(`-----BEGIN EC PUBLIC KEY-----
MEgwEgYHKoZIzj0CAQYHK4ZIzj0BAwMyAASMFI4++I8gKJLcDyhGCNh+QDdYxQIm
8ZyUqihH5ERYgEK9MTBpA/sNJOigLnPgF0E=
-----END EC PUBLIC KEY-----`))
}

func parsePrivate(priv []byte) {
k, err := parse.Private(priv)
if err != nil {
panic(err)
}

fmt.Printf(" Curve: %s\n Fingerprint: %x\n", k.Public().Name(), k.Public().Fingerprint(sha1.New()))
}

func parsePublic(pub []byte) {
k, err := parse.Public(pub)
if err != nil {
panic(err)
}

fmt.Printf(" Curve: %s\n Fingerprint: %x\n", k.Name(), k.Fingerprint(sha1.New()))
}

0 comments on commit 2bd6976

Please sign in to comment.