easypgp

package module
v0.0.0-...-54dcdcf Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

README

EasyPGP

PGP library for iOS and Android available through gomobile

To use EasyPGP you would need to install gomobile tools, following tutorial. You also need to patch gomobile to support Uint64:

diff --git a/bind/gen.go b/bind/gen.go
index 546c5cf4..0428230f 100644
--- a/bind/gen.go
+++ b/bind/gen.go
@@ -232,7 +232,9 @@ func (g *Generator) cgoType(t types.Type) string {
 			return "int64_t"
 		case types.Uint8: // types.Byte
 			return "uint8_t"
-		// TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32, types.Uint64:
+		// TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32:
+		case types.Uint64:
+			return "uint64_t"
 		case types.Float32:
 			return "float"
 		case types.Float64, types.UntypedFloat:

After that you can build EasyPGP.framework:

go get github.com/lastochkanetwork/easypgp

# For iOS
gomobile bind -target=ios -o EasyPGP.framework  github.com/lastochkanetwork/easypgp

# For Android
gomobile bind -target=android  github.com/lastochkanetwork/easypgp

After adding EasyPGP.framework to your project you can straight-forward use it.

Swift example:

let pubkey1  = "-----BEGIN PGP PUBLIC KEY BLOCK-----...."
let privkey1 = "-----BEGIN PGP PRIVATE KEY BLOCK-----...."
let pubkey2  = "-----BEGIN PGP PUBLIC KEY BLOCK-----...."
let privkey2 = "-----BEGIN PGP PRIVATE KEY BLOCK-----...."


let sender = EasypgpNewKeyPairWithKeys(pubkey1, privkey1)
let receiver = EasypgpNewKeyPairWithKeys(pubkey2, nil)
let receiver_with_privkey = EasypgpNewKeyPairWithKeys(pubkey2, privkey2)


let msg = EasypgpEncryptAndSign("hello, world!", receiver, sender, nil)
NSLog((msg?.cipher())!)

let decrypted = EasypgpDecryptAndVerify(msg, receiver_with_privkey, nil)
NSLog((decrypted?.text())!)

Documentation

Overview

Package easypgp is a generated protocol buffer package.

It is generated from these files:

easypgp.proto

It has these top-level messages:

CipherWithSignature
EncryptedMessage
DecryptedMessage

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(cipher string, recipient *KeyPair) (string, error)

func DecryptSymmetric

func DecryptSymmetric(cipher, key string) (string, error)

func EncryptSymmetric

func EncryptSymmetric(text, key string) (string, error)

func Sign

func Sign(message string, signer *KeyPair) (string, error)

func Verify

func Verify(message string, signature string, signer_pubkey string) (bool, error)

Types

type CipherWithSignature

type CipherWithSignature struct {
	Cipher    string `protobuf:"bytes,1,opt,name=cipher" json:"cipher,omitempty"`
	Signature string `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
}

func (*CipherWithSignature) Descriptor

func (*CipherWithSignature) Descriptor() ([]byte, []int)

func (*CipherWithSignature) GetCipher

func (m *CipherWithSignature) GetCipher() string

func (*CipherWithSignature) GetSignature

func (m *CipherWithSignature) GetSignature() string

func (*CipherWithSignature) ProtoMessage

func (*CipherWithSignature) ProtoMessage()

func (*CipherWithSignature) Reset

func (m *CipherWithSignature) Reset()

func (*CipherWithSignature) String

func (m *CipherWithSignature) String() string

type DecryptedMessage

type DecryptedMessage struct {
	Text        string `protobuf:"bytes,1,opt,name=text" json:"text,omitempty"`
	SignatureOk bool   `protobuf:"varint,2,opt,name=signature_ok,json=signatureOk" json:"signature_ok,omitempty"`
}

func DecryptAndVerify

func DecryptAndVerify(message *EncryptedMessage, recipient *KeyPair) (*DecryptedMessage, error)

func (*DecryptedMessage) Descriptor

func (*DecryptedMessage) Descriptor() ([]byte, []int)

func (*DecryptedMessage) GetSignatureOk

func (m *DecryptedMessage) GetSignatureOk() bool

func (*DecryptedMessage) GetText

func (m *DecryptedMessage) GetText() string

func (*DecryptedMessage) ProtoMessage

func (*DecryptedMessage) ProtoMessage()

func (*DecryptedMessage) Reset

func (m *DecryptedMessage) Reset()

func (*DecryptedMessage) String

func (m *DecryptedMessage) String() string

type EncryptedMessage

type EncryptedMessage struct {
	Content      *CipherWithSignature `protobuf:"bytes,1,opt,name=content" json:"content,omitempty"`
	SenderPubkey string               `protobuf:"bytes,2,opt,name=sender_pubkey,json=senderPubkey" json:"sender_pubkey,omitempty"`
	Timestamp    uint64               `protobuf:"varint,3,opt,name=timestamp" json:"timestamp,omitempty"`
}

func Encrypt

func Encrypt(message string, recipient *KeyPair) (*EncryptedMessage, error)

func EncryptAndSign

func EncryptAndSign(message string, recipient *KeyPair, sender *KeyPair) (*EncryptedMessage, error)

func NewEmptyEncryptedMessage

func NewEmptyEncryptedMessage() *EncryptedMessage

func (*EncryptedMessage) Descriptor

func (*EncryptedMessage) Descriptor() ([]byte, []int)

func (*EncryptedMessage) GetContent

func (m *EncryptedMessage) GetContent() *CipherWithSignature

func (*EncryptedMessage) GetSenderPubkey

func (m *EncryptedMessage) GetSenderPubkey() string

func (*EncryptedMessage) GetTimestamp

func (m *EncryptedMessage) GetTimestamp() uint64

func (*EncryptedMessage) ProtoMessage

func (*EncryptedMessage) ProtoMessage()

func (*EncryptedMessage) Reset

func (m *EncryptedMessage) Reset()

func (*EncryptedMessage) String

func (m *EncryptedMessage) String() string

func (EncryptedMessage) VerifySignature

func (msg EncryptedMessage) VerifySignature() (bool, error)

func (EncryptedMessage) VerifySignatureAgainst

func (msg EncryptedMessage) VerifySignatureAgainst(pubkey string) (bool, error)

type KeyPair

type KeyPair struct {
	Pubkey  string
	Privkey string
}

func GenerateKeyPair

func GenerateKeyPair() (*KeyPair, error)

func NewKeyPairWithKeys

func NewKeyPairWithKeys(pubkey string, privkey string) *KeyPair

Jump to

Keyboard shortcuts

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