-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50faa5b
commit 953384c
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package keygen | ||
|
||
import ( | ||
"crypto/ed25519" | ||
"encoding/hex" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func Ed25519(args ...string) error { | ||
fset := flag.NewFlagSet("gen-ed25519", flag.ContinueOnError) | ||
fset.Usage = func() { | ||
fmt.Fprint(os.Stderr, `Usage: pocryp gen-ed25519 [-out OUTPUT] [-bin] | ||
Generate ED25519 key. | ||
If -out is not specified, the output will be printed to stdout. | ||
Options: | ||
`) | ||
fset.PrintDefaults() | ||
} | ||
|
||
fOutput := fset.String("out", "", "Write the result to the file at path OUTPUT.") | ||
fBin := fset.Bool("bin", false, "Write output as binary not hex.") | ||
|
||
if err := fset.Parse(args); err != nil { | ||
return err | ||
} | ||
|
||
var w io.Writer | ||
if *fOutput == "" { | ||
w = os.Stdout | ||
} else { | ||
f, err := os.Create(*fOutput) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
w = f | ||
} | ||
|
||
key, _, err := ed25519.GenerateKey(nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if *fBin { | ||
if _, err := w.Write(key); err != nil { | ||
return err | ||
} | ||
} else { | ||
fmt.Fprintln(w, hex.EncodeToString(key)) | ||
} | ||
|
||
return nil | ||
} |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
- [x] AES | ||
- [x] RSA | ||
- [x] ED25519 | ||
|
||
# Block Cipher | ||
|
||
|