pgp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: MIT Imports: 13 Imported by: 0

README

Go PGP

Layer on top of golang.org/x/crypto/openpgp to handle a few PGP use cases.
Fork of https://github.com/jchavannes/go-pgp.

Additions
  • Support for multi key encryption
  • Expanded Key Pair with rsa value

Examples

Encryption

pgp/encrypt_test.go

Encrypt
// Create public key entity
pubEntity, _ := pgp.GetEntity(publicKeyPacket, nil)

// Encrypt message
encrypted, _ := pgp.Encrypt(pubEntity, []byte(TestMessage))
Decrypt
// Create private key entity
privEntity, _ := pgp.GetEntity([]byte(TestPublicKey), []byte(TestPrivateKey))

// Decrypt message
decrypted, _ := pgp.Decrypt(privEntity, encrypted)
Signing

pgp/sign_test.go

Sign
// Create private key entity
entity, _ := pgp.GetEntity([]byte(TestPublicKey), []byte(TestPrivateKey))

// Sign message
signature, _ := pgp.Sign(entity, []byte(TestMessage))
Verify
// Create public key packet
entity, _ := pgp.GetEntity([]byte(TestPublicKey), []byte(TestPrivateKey))

// Verify signature
err = pgp.Verify(entity, []byte(TestMessage), signature)
if err == nil {
    fmt.Println("Signature verified.")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encrypted []byte, entities ...*openpgp.Entity) ([]byte, error)

func Encrypt

func Encrypt(message []byte, entities ...*openpgp.Entity) ([]byte, error)

func GetEntity

func GetEntity(publicKey []byte, privateKey []byte) (*openpgp.Entity, error)

func Sign

func Sign(entity *openpgp.Entity, message []byte) ([]byte, error)

func Verify

func Verify(publicKeyEntity *openpgp.Entity, message []byte, signature []byte) error

Types

type KeyPair

type KeyPair struct {
	PublicKey  PublicKey
	PrivateKey PrivateKey
}

func GenerateKeyPair

func GenerateKeyPair(fullName string, comment string, email string) (KeyPair, error)

type PrivateKey

type PrivateKey struct {
	String string
	RSA    *rsa.PrivateKey
}

type PublicKey

type PublicKey struct {
	String string
	RSA    *rsa.PublicKey
}

Jump to

Keyboard shortcuts

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