Documentation ¶
Overview ¶
Package helper contains several functions with a simple interface to extend usability and compatibility with gomobile
Index ¶
- Constants
- func DecryptAttachment(keyPacket []byte, dataPacket []byte, keyRing *crypto.KeyRing) (*crypto.PlainMessage, error)
- func DecryptAttachmentWithKey(privateKey string, passphrase, keyPacket, dataPacket []byte) (attachment []byte, err error)
- func DecryptBinaryMessageArmored(privateKey string, passphrase []byte, ciphertext string) ([]byte, error)
- func DecryptMessageArmored(privateKey string, passphrase []byte, ciphertext string) (string, error)
- func DecryptMessageWithPassword(password []byte, ciphertext string) (plaintext string, err error)
- func DecryptSessionKey(privateKey string, passphrase, encryptedSessionKey []byte) (sessionKey *crypto.SessionKey, err error)
- func DecryptVerifyArmoredDetached(publicKey, privateKey string, passphrase []byte, ciphertextArmored string, ...) (plainData []byte, err error)
- func DecryptVerifyAttachment(publicKey, privateKey string, passphrase, keyPacket, dataPacket []byte, ...) (plainData []byte, err error)
- func DecryptVerifyBinaryDetached(publicKey, privateKey string, passphrase []byte, encryptedData []byte, ...) (plainData []byte, err error)
- func DecryptVerifyMessageArmored(publicKey, privateKey string, passphrase []byte, ciphertext string) (plaintext string, err error)
- func EncryptAttachment(plainData []byte, filename string, keyRing *crypto.KeyRing) (*crypto.PGPSplitMessage, error)
- func EncryptAttachmentWithKey(publicKey string, filename string, plainData []byte) (message *crypto.PGPSplitMessage, err error)
- func EncryptBinaryMessageArmored(key string, data []byte) (string, error)
- func EncryptMessageArmored(key, plaintext string) (string, error)
- func EncryptMessageWithPassword(password []byte, plaintext string) (ciphertext string, err error)
- func EncryptPGPMessageToAdditionalKey(messageToModify *crypto.PGPSplitMessage, keyRing *crypto.KeyRing, ...) error
- func EncryptSessionKey(publicKey string, sessionKey *crypto.SessionKey) (encryptedSessionKey []byte, err error)
- func EncryptSignArmoredDetached(publicKey, privateKey string, passphrase, plainData []byte) (ciphertextArmored, encryptedSignatureArmored string, err error)
- func EncryptSignAttachment(publicKey, privateKey string, passphrase []byte, filename string, ...) (keyPacket, dataPacket, signature []byte, err error)
- func EncryptSignBinaryDetached(publicKey, privateKey string, passphrase, plainData []byte) (encryptedData []byte, encryptedSignatureArmored string, err error)
- func EncryptSignMessageArmored(publicKey, privateKey string, passphrase []byte, plaintext string) (ciphertext string, err error)
- func FreeOSMemory()
- func GenerateKey(name, email string, passphrase []byte, keyType string, bits int) (string, error)
- func GetJsonSHA256Fingerprints(publicKey string) ([]byte, error)
- func GetSHA256Fingerprints(publicKey string) ([]string, error)
- func QuickCheckDecrypt(sessionKey *crypto.SessionKey, prefix []byte) (bool, error)
- func QuickCheckDecryptReader(sessionKey *crypto.SessionKey, prefixReader crypto.Reader) (bool, error)
- func SignCleartextMessage(keyRing *crypto.KeyRing, text string) (string, error)
- func SignCleartextMessageArmored(privateKey string, passphrase []byte, text string) (string, error)
- func UpdatePrivateKeyPassphrase(privateKey string, oldPassphrase, newPassphrase []byte) (string, error)
- func VerifyCleartextMessage(keyRing *crypto.KeyRing, armored string, verifyTime int64) (string, error)
- func VerifyCleartextMessageArmored(publicKey, armored string, verifyTime int64) (string, error)
- func VerifySignatureExplicit(reader *crypto.PlainMessageReader) (signatureVerificationError *crypto.SignatureVerificationError, err error)
- type EncryptSignArmoredDetachedMobileResult
- type EncryptSignBinaryDetachedMobileResult
- type ExplicitVerifyMessage
- func DecryptExplicitVerify(pgpMessage *crypto.PGPMessage, privateKeyRing, publicKeyRing *crypto.KeyRing, ...) (*ExplicitVerifyMessage, error)
- func DecryptExplicitVerifyWithContext(pgpMessage *crypto.PGPMessage, privateKeyRing, publicKeyRing *crypto.KeyRing, ...) (*ExplicitVerifyMessage, error)
- func DecryptSessionKeyExplicitVerify(dataPacket []byte, sessionKey *crypto.SessionKey, ...) (*ExplicitVerifyMessage, error)
- func DecryptSessionKeyExplicitVerifyWithContext(dataPacket []byte, sessionKey *crypto.SessionKey, ...) (*ExplicitVerifyMessage, error)
- type Go2AndroidReader
- type Go2IOSReader
- type Mobile2GoReader
- type Mobile2GoWriter
- type Mobile2GoWriterWithSHA256
- type MobileReadResult
- type MobileReader
Constants ¶
const AES_BLOCK_SIZE = 16
Variables ¶
This section is empty.
Functions ¶
func DecryptAttachment ¶
func DecryptAttachment(keyPacket []byte, dataPacket []byte, keyRing *crypto.KeyRing) (*crypto.PlainMessage, error)
DecryptAttachment takes a keypacket and datpacket and returns a decrypted PlainMessage Specifically designed for attachments rather than text messages.
func DecryptAttachmentWithKey ¶ added in v2.1.0
func DecryptAttachmentWithKey( privateKey string, passphrase, keyPacket, dataPacket []byte, ) (attachment []byte, err error)
DecryptAttachmentWithKey decrypts a binary file Using a given armored private key and its passphrase.
func DecryptBinaryMessageArmored ¶ added in v2.1.0
func DecryptBinaryMessageArmored(privateKey string, passphrase []byte, ciphertext string) ([]byte, error)
DecryptBinaryMessageArmored decrypts an armored PGP message given a private key and its passphrase.
func DecryptMessageArmored ¶
func DecryptMessageArmored( privateKey string, passphrase []byte, ciphertext string, ) (string, error)
DecryptMessageArmored decrypts an armored PGP message given a private key and its passphrase.
func DecryptMessageWithPassword ¶
DecryptMessageWithPassword decrypts an armored message with a random token. The algorithm is derived from the armoring.
func DecryptSessionKey ¶ added in v2.1.0
func DecryptSessionKey( privateKey string, passphrase, encryptedSessionKey []byte, ) (sessionKey *crypto.SessionKey, err error)
DecryptSessionKey decrypts a session key using a given armored private key and its passphrase.
func DecryptVerifyArmoredDetached ¶ added in v2.1.0
func DecryptVerifyArmoredDetached( publicKey, privateKey string, passphrase []byte, ciphertextArmored string, encryptedSignatureArmored string, ) (plainData []byte, err error)
DecryptVerifyArmoredDetached decrypts an armored pgp message and verify a detached armored encrypted signature given a publicKey, and a privateKey with its passphrase. Returns the plain data or an error on signature verification failure.
func DecryptVerifyAttachment ¶
func DecryptVerifyAttachment( publicKey, privateKey string, passphrase, keyPacket, dataPacket []byte, armoredSignature string, ) (plainData []byte, err error)
DecryptVerifyAttachment decrypts and verifies an attachment split into the keyPacket, dataPacket and an armored (!) signature, given a publicKey, and a privateKey with its passphrase. Returns the plain data or an error on signature verification failure.
func DecryptVerifyBinaryDetached ¶ added in v2.1.0
func DecryptVerifyBinaryDetached( publicKey, privateKey string, passphrase []byte, encryptedData []byte, encryptedSignatureArmored string, ) (plainData []byte, err error)
DecryptVerifyBinaryDetached decrypts binary encrypted data and verify a detached armored encrypted signature given a publicKey, and a privateKey with its passphrase. Returns the plain data or an error on signature verification failure.
func DecryptVerifyMessageArmored ¶
func DecryptVerifyMessageArmored( publicKey, privateKey string, passphrase []byte, ciphertext string, ) (plaintext string, err error)
DecryptVerifyMessageArmored decrypts an armored PGP message given a private key and its passphrase and verifies the embedded signature. Returns the plain data or an error on signature verification failure.
func EncryptAttachment ¶
func EncryptAttachment(plainData []byte, filename string, keyRing *crypto.KeyRing) (*crypto.PGPSplitMessage, error)
EncryptAttachment encrypts a file given a plainData and a fileName. Returns a PGPSplitMessage containing a session key packet and symmetrically encrypted data. Specifically designed for attachments rather than text messages.
func EncryptAttachmentWithKey ¶ added in v2.1.0
func EncryptAttachmentWithKey( publicKey string, filename string, plainData []byte, ) (message *crypto.PGPSplitMessage, err error)
EncryptAttachmentWithKey encrypts a binary file Using a given armored public key.
func EncryptBinaryMessageArmored ¶ added in v2.1.0
EncryptBinaryMessageArmored generates an armored PGP message given a binary data and an armored public key.
func EncryptMessageArmored ¶
EncryptMessageArmored generates an armored PGP message given a plaintext and an armored public key.
func EncryptMessageWithPassword ¶
EncryptMessageWithPassword encrypts a string with a passphrase using AES256.
func EncryptPGPMessageToAdditionalKey ¶ added in v2.7.5
func EncryptPGPMessageToAdditionalKey(messageToModify *crypto.PGPSplitMessage, keyRing *crypto.KeyRing, additionalKey *crypto.KeyRing) error
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 EncryptSessionKey ¶ added in v2.1.0
func EncryptSessionKey( publicKey string, sessionKey *crypto.SessionKey, ) (encryptedSessionKey []byte, err error)
EncryptSessionKey encrypts a session key using a given armored public key.
func EncryptSignArmoredDetached ¶ added in v2.1.0
func EncryptSignArmoredDetached( publicKey, privateKey string, passphrase, plainData []byte, ) (ciphertextArmored, encryptedSignatureArmored string, err error)
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 EncryptSignAttachment ¶
func EncryptSignAttachment( publicKey, privateKey string, passphrase []byte, filename string, plainData []byte, ) (keyPacket, dataPacket, signature []byte, err error)
EncryptSignAttachment encrypts an attachment using a detached signature, given a publicKey, a privateKey and its passphrase, the filename, and the unencrypted file data. Returns keypacket, dataPacket and unarmored (!) signature separate.
func EncryptSignBinaryDetached ¶ added in v2.1.0
func EncryptSignBinaryDetached( publicKey, privateKey string, passphrase, plainData []byte, ) (encryptedData []byte, encryptedSignatureArmored string, err error)
EncryptSignBinaryDetached takes a public key for encryption, a private key and its passphrase for signature, and the plaintext data Returns encrypted binary data and a detached armored encrypted signature.
func EncryptSignMessageArmored ¶
func EncryptSignMessageArmored( publicKey, privateKey string, passphrase []byte, plaintext string, ) (ciphertext string, err error)
EncryptSignMessageArmored generates an armored signed PGP message given a plaintext and an armored public key a private key and its passphrase.
func FreeOSMemory ¶ added in v2.1.3
func FreeOSMemory()
FreeOSMemory can be used to explicitly call the garbage collector and return the unused memory to the OS.
func GenerateKey ¶
GenerateKey generates a key of the given keyType ("rsa" or "x25519"), encrypts it, and returns an armored string. If keyType is "rsa", bits is the RSA bitsize of the key. If keyType is "x25519" bits is unused.
func GetJsonSHA256Fingerprints ¶ added in v2.0.1
GetJsonSHA256Fingerprints returns the SHA256 fingeprints of key and subkeys, encoded in JSON, since gomobile can not handle arrays.
func GetSHA256Fingerprints ¶ added in v2.0.1
func QuickCheckDecrypt ¶ added in v2.7.3
func QuickCheckDecrypt(sessionKey *crypto.SessionKey, prefix []byte) (bool, error)
QuickCheckDecrypt checks with high probability if the provided session key can decrypt the encrypted data packet given its 24 byte long prefix. The method only considers the first 24 bytes of the prefix slice (prefix[:24]). NOTE: Only works for SEIPDv1 packets with AES.
func QuickCheckDecryptReader ¶ added in v2.7.3
func QuickCheckDecryptReader(sessionKey *crypto.SessionKey, prefixReader crypto.Reader) (bool, error)
QuickCheckDecryptReader checks with high probability if the provided session key can decrypt a data packet given its 24 byte long prefix. The method reads up to but not exactly 24 bytes from the prefixReader. NOTE: Only works for SEIPDv1 packets with AES.
func SignCleartextMessage ¶
SignCleartextMessage signs text given a private keyring, canonicalizes and trims the newlines, and returns the PGP-compliant special armoring.
func SignCleartextMessageArmored ¶
SignCleartextMessageArmored signs text given a private key and its passphrase, canonicalizes and trims the newlines, and returns the PGP-compliant special armoring.
func UpdatePrivateKeyPassphrase ¶
func UpdatePrivateKeyPassphrase( privateKey string, oldPassphrase, newPassphrase []byte, ) (string, error)
UpdatePrivateKeyPassphrase decrypts the given armored privateKey with oldPassphrase, re-encrypts it with newPassphrase, and returns the new armored key.
func VerifyCleartextMessage ¶
func VerifyCleartextMessage(keyRing *crypto.KeyRing, armored string, verifyTime int64) (string, error)
VerifyCleartextMessage verifies PGP-compliant armored signed plain text given the public keyring and returns the text or err if the verification fails.
func VerifyCleartextMessageArmored ¶
VerifyCleartextMessageArmored verifies PGP-compliant armored signed plain text given the public key and returns the text or err if the verification fails.
func VerifySignatureExplicit ¶ added in v2.2.1
func VerifySignatureExplicit( reader *crypto.PlainMessageReader, ) (signatureVerificationError *crypto.SignatureVerificationError, err error)
VerifySignatureExplicit calls the reader's VerifySignature() and tries to cast the returned error to a SignatureVerificationError.
Types ¶
type EncryptSignArmoredDetachedMobileResult ¶ added in v2.1.0
type EncryptSignArmoredDetachedMobileResult struct {
CiphertextArmored, EncryptedSignatureArmored string
}
func EncryptSignArmoredDetachedMobile ¶ added in v2.1.0
func EncryptSignArmoredDetachedMobile( publicKey, privateKey string, passphrase, plainData []byte, ) (wrappedTuple *EncryptSignArmoredDetachedMobileResult, err error)
EncryptSignArmoredDetachedMobile wraps the encryptSignArmoredDetached method to have only one return argument for mobile.
type EncryptSignBinaryDetachedMobileResult ¶ added in v2.1.0
type EncryptSignBinaryDetachedMobileResult struct { EncryptedData []byte EncryptedSignatureArmored string }
func EncryptSignBinaryDetachedMobile ¶ added in v2.1.0
func EncryptSignBinaryDetachedMobile( publicKey, privateKey string, passphrase, plainData []byte, ) (wrappedTuple *EncryptSignBinaryDetachedMobileResult, err error)
EncryptSignBinaryDetachedMobile wraps the encryptSignBinaryDetached method to have only one return argument for mobile.
type ExplicitVerifyMessage ¶
type ExplicitVerifyMessage struct { Message *crypto.PlainMessage SignatureVerificationError *crypto.SignatureVerificationError }
func DecryptExplicitVerify ¶
func DecryptExplicitVerify( pgpMessage *crypto.PGPMessage, privateKeyRing, publicKeyRing *crypto.KeyRing, verifyTime int64, ) (*ExplicitVerifyMessage, error)
DecryptExplicitVerify decrypts a PGP message given a private keyring and a public keyring to verify the embedded signature. Returns the plain data and an error on signature verification failure.
func DecryptExplicitVerifyWithContext ¶ added in v2.7.1
func DecryptExplicitVerifyWithContext( pgpMessage *crypto.PGPMessage, privateKeyRing, publicKeyRing *crypto.KeyRing, verifyTime int64, verificationContext *crypto.VerificationContext, ) (*ExplicitVerifyMessage, error)
DecryptExplicitVerifyWithContext decrypts a PGP message given a private keyring and a public keyring to verify the embedded signature. Returns the plain data and an error on signature verification failure. The caller can provide a context that will be used to verify the signature.
func DecryptSessionKeyExplicitVerify ¶ added in v2.1.8
func DecryptSessionKeyExplicitVerify( dataPacket []byte, sessionKey *crypto.SessionKey, publicKeyRing *crypto.KeyRing, verifyTime int64, ) (*ExplicitVerifyMessage, error)
DecryptSessionKeyExplicitVerify decrypts a PGP data packet given a session key and a public keyring to verify the embedded signature. Returns the plain data and an error on signature verification failure.
func DecryptSessionKeyExplicitVerifyWithContext ¶ added in v2.7.1
func DecryptSessionKeyExplicitVerifyWithContext( dataPacket []byte, sessionKey *crypto.SessionKey, publicKeyRing *crypto.KeyRing, verifyTime int64, verificationContext *crypto.VerificationContext, ) (*ExplicitVerifyMessage, error)
DecryptSessionKeyExplicitVerifyWithContext decrypts a PGP data packet given a session key and a public keyring to verify the embedded signature. Returns the plain data and an error on signature verification failure. The caller can provide a context that will be used to verify the signature.
type Go2AndroidReader ¶ added in v2.2.0
type Go2AndroidReader struct {
// contains filtered or unexported fields
}
Go2AndroidReader is used to wrap a native golang Reader in the golang runtime, to be usable in the android app runtime (via gomobile).
func NewGo2AndroidReader ¶ added in v2.2.0
func NewGo2AndroidReader(reader crypto.Reader) *Go2AndroidReader
NewGo2AndroidReader wraps a native golang Reader to be usable in the mobile app runtime (via gomobile). It doesn't follow the standard golang Reader behavior, and returns n = -1 on EOF.
type Go2IOSReader ¶ added in v2.2.0
type Go2IOSReader struct {
// contains filtered or unexported fields
}
Go2IOSReader is used to wrap a native golang Reader in the golang runtime, to be usable in the iOS app runtime (via gomobile) as a MobileReader.
func NewGo2IOSReader ¶ added in v2.2.0
func NewGo2IOSReader(reader crypto.Reader) *Go2IOSReader
NewGo2IOSReader wraps a native golang Reader to be usable in the ios app runtime (via gomobile).
func (*Go2IOSReader) Read ¶ added in v2.2.0
func (r *Go2IOSReader) Read(max int) (result *MobileReadResult, err error)
Read reads at most <max> bytes from the wrapped Reader and returns the read data as a MobileReadResult.
type Mobile2GoReader ¶ added in v2.2.0
type Mobile2GoReader struct {
// contains filtered or unexported fields
}
Mobile2GoReader is used to wrap a MobileReader in the mobile app runtime, to be usable in the golang runtime (via gomobile) as a native Reader.
func NewMobile2GoReader ¶ added in v2.2.0
func NewMobile2GoReader(reader MobileReader) *Mobile2GoReader
NewMobile2GoReader wraps a MobileReader to be usable in the golang runtime (via gomobile).
type Mobile2GoWriter ¶ added in v2.2.0
type Mobile2GoWriter struct {
// contains filtered or unexported fields
}
Mobile2GoWriter is used to wrap a writer in the mobile app runtime, to be usable in the golang runtime (via gomobile).
func NewMobile2GoWriter ¶ added in v2.2.0
func NewMobile2GoWriter(writer crypto.Writer) *Mobile2GoWriter
NewMobile2GoWriter wraps a writer to be usable in the golang runtime (via gomobile).
type Mobile2GoWriterWithSHA256 ¶ added in v2.2.0
type Mobile2GoWriterWithSHA256 struct {
// contains filtered or unexported fields
}
Mobile2GoWriterWithSHA256 is used to wrap a writer in the mobile app runtime, to be usable in the golang runtime (via gomobile). It also computes the SHA256 hash of the data being written on the fly.
func NewMobile2GoWriterWithSHA256 ¶ added in v2.2.0
func NewMobile2GoWriterWithSHA256(writer crypto.Writer) *Mobile2GoWriterWithSHA256
NewMobile2GoWriterWithSHA256 wraps a writer to be usable in the golang runtime (via gomobile). The wrapper also computes the SHA256 hash of the data being written on the fly.
func (*Mobile2GoWriterWithSHA256) GetSHA256 ¶ added in v2.2.0
func (w *Mobile2GoWriterWithSHA256) GetSHA256() []byte
GetSHA256 returns the SHA256 hash of the data that's been written so far.
func (*Mobile2GoWriterWithSHA256) Write ¶ added in v2.2.0
func (w *Mobile2GoWriterWithSHA256) Write(b []byte) (n int, err error)
Write writes the data in the provided buffer in the wrapped writer. It clones the provided data to prevent errors with garbage collectors. It also computes the SHA256 hash of the data being written on the fly.
type MobileReadResult ¶ added in v2.2.0
type MobileReadResult struct { N int // N, The number of bytes read IsEOF bool // IsEOF, If true, then the reader has reached the end of the data to read. Data []byte // Data, the data that has been read }
MobileReadResult is what needs to be returned by MobileReader.Read. The read data is passed as a return value rather than passed as an argument to the reader. This avoids problems introduced by gomobile that prevent the use of native golang readers.
func NewMobileReadResult ¶ added in v2.2.0
func NewMobileReadResult(n int, eof bool, data []byte) *MobileReadResult
NewMobileReadResult initialize a MobileReadResult with the correct values. It clones the data to avoid the garbage collector freeing the data too early.
type MobileReader ¶ added in v2.2.0
type MobileReader interface {
Read(max int) (result *MobileReadResult, err error)
}
MobileReader is the interface that readers in the mobile runtime must use and implement. This is a workaround to some of the gomobile limitations.