I wrote a Go function to encrypt a string using a public DSA key. I understand DSA keys are meant for signing but command line encryption seems to be working fine with the DSA key. I wanted to check if openpgp or any other crypto package in Go can be used to encrypt using a public DSA key. Here is the code I wrote using this example
//encrypt data
//TODO: Change to io.Reade io.Writer interface
func EncryptData(ctx context.Context, fileBuffer string, KeyName string) (string, error) {
var entityList openpgp.EntityList
//get private key from Google secrets manager
signingkey, err := GetSAKey(ctx, KeyName)
if err != nil {
return "", errors.New("ERV003: Error accessing private key from secrets manager : " + err.Error())
}
//get ascii armored keyring
entityList, err1 := openpgp.ReadArmoredKeyRing(strings.NewReader(signingkey))
if err1 != nil {
return "", errors.New("ERV005: Error reading GPG private key : " + err1.Error())
}
buf := new(bytes.Buffer)
w, err := openpgp.Encrypt(buf, entityList, nil, nil, nil)
if err != nil {
return "", errors.New("ERV006: Error ecrypting file data : " + err.Error())
}
_, err = w.Write([]byte(fileBuffer))
err = w.Close()
if err != nil {
return "", err
}
// Encode to base64
bytes, err := ioutil.ReadAll(buf)
if err != nil {
return "", err
}
encStr := base64.StdEncoding.EncodeToString(bytes)
// Output encrypted/encoded string
log.Println("Encrypted Secret:", encStr)
return encStr, nil
}
I am getting the below error
openpgp: invalid argument: cannot encrypt to public key of type 17
This works fine with RSA keys. But my requirement is to use a DSA key.