passforios-gopenpgp/helper/message.go
Lukas Burkhalter c6a3058e2e
Prepare release 2.7.5 with packet API (#269)
Adds the following API functions:
- API to get signature key IDs for mobile:
	func (msg *PGPMessage) GetHexSignatureKeyIDsJson() []byte

- API to get encryption key IDs for mobile:
	func (msg *PGPMessage) GetHexEncryptionKeyIDsJson() []byte

- API to get the number of key packets in a PGP message:
	func (msg *PGPSplitMessage) GetNumberOfKeyPackets() (int, error)

- API in package `helper` to encrypt a PGP message to an additional key:
	func EncryptPGPMessageToAdditionalKey(messageToModify *crypto.PGPSplitMessage, keyRing *crypto.KeyRing, additionalKey *crypto.KeyRing) error
2024-02-07 08:09:26 +01:00

22 lines
1 KiB
Go

package helper
import "github.com/ProtonMail/gopenpgp/v2/crypto"
// EncryptPGPMessageToAdditionalKey decrypts the session key of the input PGPSplitMessage with a private key in keyRing
// and encrypts it towards the additionalKeys by adding the additional key packets to the input PGPSplitMessage.
// If successful, new key packets are added to message.
// * messageToModify : The encrypted pgp message that should be modified
// * keyRing : The private keys to decrypt the session key in the messageToModify.
// * additionalKey : The public keys the message should be additionally encrypted to.
func EncryptPGPMessageToAdditionalKey(messageToModify *crypto.PGPSplitMessage, keyRing *crypto.KeyRing, additionalKey *crypto.KeyRing) error {
sessionKey, err := keyRing.DecryptSessionKey(messageToModify.KeyPacket)
if err != nil {
return err
}
additionalKeyPacket, err := additionalKey.EncryptSessionKey(sessionKey)
if err != nil {
return err
}
messageToModify.KeyPacket = append(messageToModify.KeyPacket, additionalKeyPacket...)
return nil
}