Created
July 10, 2019 07:09
-
-
Save burubur/3ed3bc5a7104034aee1e7fb0da0745a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func main() { | |
| privateKeyFile, err := os.Open("privatekey.asc") | |
| if err != nil { | |
| log.Println("failed to open privateKey") | |
| log.Printf("err: %v", err) | |
| } | |
| defer func() { | |
| _ = privateKeyFile.Close() | |
| }() | |
| //privateKey := string(privateKeyFile) | |
| //fmt.Printf("privateKey: %s\v", privateKey) | |
| entityList, err := openpgp.ReadArmoredKeyRing(privateKeyFile) | |
| if err != nil { | |
| log.Println("failed to read keyRing") | |
| log.Printf("err: %v", err) | |
| } | |
| //entityList, err := openpgp.ReadKeyRing(privateKeyFile) | |
| //if err != nil { | |
| // log.Println("failed to read keyRing") | |
| // log.Printf("err: %v", err) | |
| //} | |
| //entity := entityList[0] | |
| //err = entity.PrivateKey.Decrypt([]byte{}) | |
| //if err != nil { | |
| // log.Println("error while decrypting empty passphrase") | |
| //} | |
| fmt.Printf("entity list: %v\n", entityList) | |
| ctFile, err := os.Open("ciphertext.pgp") | |
| if err != nil { | |
| log.Println("error while opening ciphertext") | |
| } | |
| buf := new(bytes.Buffer) | |
| _, err = buf.ReadFrom(ctFile) | |
| if err != nil { | |
| log.Println("error while reading buffer") | |
| } | |
| cipherText := buf.Bytes() | |
| md, e := openpgp.ReadMessage(bytes.NewBuffer(cipherText), entityList, nil, nil) | |
| if e != nil { | |
| log.Println("error while reading message") | |
| log.Printf("err: %v", e) | |
| } | |
| log.Printf("message: %v\n", md) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment