Created
May 24, 2021 13:40
-
-
Save rvflash/a9fe02faca81b1636d1d92f8a7837fb6 to your computer and use it in GitHub Desktop.
Command line to convert a private OpenPGP key in its representation in armor.
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"golang.org/x/crypto/openpgp" | |
"golang.org/x/crypto/openpgp/armor" | |
) | |
func openPGPArmored(filename string) error { | |
if filename == "" { | |
return io.EOF | |
} | |
f, err := os.Open(filename) | |
if err != nil { | |
return err | |
} | |
defer func() { _ = f.Close() }() | |
w, err := armor.Encode(os.Stdout, openpgp.PrivateKeyType, nil) | |
if err != nil { | |
return fmt.Errorf("openpgp: begin armor: %s", err) | |
} | |
defer func() { _ = w.Close() }() | |
b, err := io.ReadAll(f) | |
if err != nil { | |
return fmt.Errorf("openpgp: key file: %s", err) | |
} | |
_, err = w.Write(b) | |
if err != nil { | |
return fmt.Errorf("openpgp: writing key: %s", err) | |
} | |
return nil | |
} | |
func main() { | |
flag.Parse() | |
err := openPGPArmored(flag.Arg(0)) | |
if err != nil { | |
log.Fatalln(err.Error()) | |
} | |
os.Exit(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment