helper

package
Version: v2.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 5 Imported by: 7

Documentation

Overview

Package helper contains several functions with a simple interface to extend usability and compatibility with gomobile

Index

Constants

This section is empty.

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

func DecryptMessageWithPassword(password []byte, ciphertext string) (plaintext string, err error)

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

func EncryptBinaryMessageArmored(key string, data []byte) (string, error)

EncryptBinaryMessageArmored generates an armored PGP message given a binary data and an armored public key.

func EncryptMessageArmored

func EncryptMessageArmored(key, plaintext string) (string, error)

EncryptMessageArmored generates an armored PGP message given a plaintext and an armored public key.

func EncryptMessageWithPassword

func EncryptMessageWithPassword(password []byte, plaintext string) (ciphertext string, err error)

EncryptMessageWithPassword encrypts a string with a passphrase using AES256.

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

func GenerateKey(name, email string, passphrase []byte, keyType string, bits int) (string, error)

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

func GetJsonSHA256Fingerprints(publicKey string) ([]byte, error)

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 GetSHA256Fingerprints(publicKey string) ([]string, error)

func SignCleartextMessage

func SignCleartextMessage(keyRing *crypto.KeyRing, text string) (string, error)

SignCleartextMessage signs text given a private keyring, canonicalizes and trims the newlines, and returns the PGP-compliant special armoring.

func SignCleartextMessageArmored

func SignCleartextMessageArmored(privateKey string, passphrase []byte, text string) (string, error)

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

func VerifyCleartextMessageArmored(publicKey, armored string, verifyTime int64) (string, error)

VerifyCleartextMessageArmored verifies PGP-compliant armored signed plain text given the public key and returns the text or err if the verification fails.

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL