github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/secrets/pgp.go (about)

     1  package secrets
     2  
     3  import (
     4  	"github.com/ProtonMail/gopenpgp/v2/crypto"
     5  )
     6  
     7  func GeneratePGPKey(
     8  	fullName,
     9  	email,
    10  	password string,
    11  ) (string, string, error) {
    12  	rawPGPKey, err := crypto.GenerateKey(
    13  		fullName,
    14  		email,
    15  		"x25519",
    16  		0,
    17  	)
    18  	if err != nil {
    19  		return "", "", err
    20  	}
    21  	defer rawPGPKey.ClearPrivateParams()
    22  
    23  	lockedPGPKey, err := rawPGPKey.Lock([]byte(password))
    24  	if err != nil {
    25  		return "", "", err
    26  	}
    27  
    28  	armoredPGPKey, err := lockedPGPKey.Armor()
    29  	if err != nil {
    30  		return "", "", err
    31  	}
    32  
    33  	return armoredPGPKey, rawPGPKey.GetHexKeyID(), nil
    34  }