Merge pull request #6 from DeCentral-Budapest/master

Added Ed25519 key type
This commit is contained in:
Jeromy Johnson 2016-12-20 12:30:11 -08:00 committed by GitHub
commit e8d4b720f1
2 changed files with 35 additions and 9 deletions

View File

@ -1,16 +1,39 @@
# ipfs-key # ipfs-key
A tool for easily generating ipfs keypairs. When run, it will write the bytes of
the serialized private key to stdout. By default, a 2048 bit RSA key will be [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
generated. The keysize can be changed by specifying the `-bitsize` option, and the
key type can be changed by specifying the `-type` option (currently only RSA is > A tool for easily generating ipfs keypairs
implemented).
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)
## Installation ## Installation
``` ```
$ go get github.com/whyrusleeping/ipfs-key $ go get github.com/whyrusleeping/ipfs-key
``` ```
## Usage ## Usage
When run, it will write the bytes of
the serialized private key to stdout. By default, a 2048 bit RSA key will be
generated. In this case the key size can be changed by specifying the `-bitsize`
option. The key type can be changed by specifying the `-type` option (rsa or
ed25519).
``` ```
$ ipfs-key -bitsize=4096 > my.key $ ipfs-key -bitsize=4096 > my-rsa4096.key
$ ipfs-key -type=ed25519 > my-ed.key
``` ```
## Contribute
PRs accepted.
## License
[MIT](LICENSE) Copyright (c) 2016 [Jeromy Johnson](http://github.com/whyrusleeping)

View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"strings"
ci "github.com/libp2p/go-libp2p-crypto" ci "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
@ -11,14 +12,16 @@ import (
func main() { func main() {
size := flag.Int("bitsize", 2048, "select the bitsize of the key to generate") size := flag.Int("bitsize", 2048, "select the bitsize of the key to generate")
typ := flag.String("type", "RSA", "select type of key to generate") typ := flag.String("type", "RSA", "select type of key to generate (RSA or Ed25519)")
flag.Parse() flag.Parse()
var atyp int var atyp int
switch *typ { switch strings.ToLower(*typ) {
case "RSA": case "rsa":
atyp = ci.RSA atyp = ci.RSA
case "ed25519":
atyp = ci.Ed25519
default: default:
fmt.Fprintln(os.Stderr, "unrecognized key type: ", *typ) fmt.Fprintln(os.Stderr, "unrecognized key type: ", *typ)
os.Exit(1) os.Exit(1)