diff --git a/helper/helper.go b/helper/helper.go index 016bc33..0a4a316 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -184,6 +184,28 @@ func DecryptBinaryMessageArmored(privateKey string, passphrase []byte, ciphertex return message.GetBinary(), nil } +// encryptSignArmoredDetached takes a public key for encryption, +// a private key and its passphrase for signature, and the plaintext data +// Returns an armored ciphertext and a detached armored signature. +func encryptSignArmoredDetached( + publicKey, privateKey string, + passphrase, plainData []byte, +) (ciphertext, signature string, err error) { + var message *crypto.PlainMessage = crypto.NewPlainMessage(plainData) + + // We encrypt the message + if ciphertext, err = encryptMessageArmored(publicKey, message); err != nil { + return "", "", err + } + + // We sign the message + if signature, err = signDetachedArmored(privateKey, passphrase, message); err != nil { + return "", "", err + } + + return ciphertext, signature, nil +} + // DecryptVerifyArmoredDetached decrypts an armored pgp message // and verify a detached armored signature // given a publicKey, and a privateKey with its passphrase. diff --git a/helper/mobile.go b/helper/mobile.go index 33004bb..c53f8a6 100644 --- a/helper/mobile.go +++ b/helper/mobile.go @@ -90,7 +90,7 @@ func EncryptSignArmoredDetachedMobile( publicKey, privateKey string, passphrase, plainData []byte, ) (wrappedTuple *EncryptSignArmoredDetachedMobileResult, err error) { - ciphertext, signature, err := EncryptSignArmoredDetached(publicKey, privateKey, passphrase, plainData) + ciphertext, signature, err := encryptSignArmoredDetached(publicKey, privateKey, passphrase, plainData) if err != nil { return nil, err } diff --git a/helper/sign_detached.go b/helper/sign_detached.go index 216ebe2..8c078e7 100644 --- a/helper/sign_detached.go +++ b/helper/sign_detached.go @@ -63,17 +63,5 @@ func EncryptSignArmoredDetached( publicKey, privateKey string, passphrase, plainData []byte, ) (ciphertext, signature string, err error) { - var message *crypto.PlainMessage = crypto.NewPlainMessage(plainData) - - // We encrypt the message - if ciphertext, err = encryptMessageArmored(publicKey, message); err != nil { - return "", "", err - } - - // We sign the message - if signature, err = signDetachedArmored(privateKey, passphrase, message); err != nil { - return "", "", err - } - - return ciphertext, signature, nil + return encryptSignArmoredDetached(publicKey, privateKey, passphrase, plainData) }