feat: initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v3/crypto"
|
||||
)
|
||||
|
||||
const keyFile = "pubkey.asc"
|
||||
|
||||
func generateFile() string {
|
||||
return "this is a file"
|
||||
}
|
||||
|
||||
func encryptFile(content string) []byte {
|
||||
publicKeyArmored, err := os.ReadFile(keyFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
publicKey, err := crypto.NewKeyFromArmored(string(publicKeyArmored))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pgp := crypto.PGP()
|
||||
enc, err := pgp.Encryption().Recipient(publicKey).New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
message, err := enc.Encrypt([]byte(content))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
messageArmored, err := message.ArmorBytes()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return messageArmored
|
||||
}
|
||||
|
||||
func main() {
|
||||
content := generateFile()
|
||||
encrypted := encryptFile(content)
|
||||
err := os.WriteFile("data.gpg", encrypted, 0600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user