My goal is to use read a PEM file (which contains a private key) and a passphrase to clearsign a file and then use openpgp to encrypt it using a public key that has been provided to me.
I know I should use block, _ := pem.Decode([]byte(pemFile))
to read the file and the ParsePKCS1PrivateKey
but I am not sure how to clear sign the file using the key and the passphrase and then encrypt the signed using golang.org/x/crypto/openpgp
Reading the pem file and creating a private key is straightforward:
data, err := ioutil.ReadFile("myPemFile")
block, _ := pem.Decode([]byte(data))
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
where the key is *rsa.PrivateKey
. The question is how to use a passphrase and the private key to clear sign a file i.e. doing something equivalent to:
gpg --batch --passphrase-file <passfile> --clearsign <unsigned file>