ecies

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data []byte, priv *PrivateKey, ecdh ECDH, kdf KDF) ([]byte, error)

Decrypt decrypts ciphertext by receiver private key

func DecryptBase64 added in v0.3.1

func DecryptBase64(ciphertext string, priv *PrivateKey, ecdh ECDH, kdf KDF) ([]byte, error)

DecryptBase64 decrypts ciphertext in base64 form to raw data([]byte) by receiver private key

func DecryptBase64String added in v0.2.0

func DecryptBase64String(ciphertext string, priv *PrivateKey, ecdh ECDH, kdf KDF) (string, error)

DecryptBase64String decrypts ciphertext in base64 form to plaintext by receiver private key

func DecryptHex added in v0.3.1

func DecryptHex(ciphertext string, priv *PrivateKey, ecdh ECDH, kdf KDF) ([]byte, error)

DecryptHex decrypts ciphertext in hex form to raw data([]byte) by receiver private key

func DecryptHexString added in v0.2.0

func DecryptHexString(ciphertext string, priv *PrivateKey, ecdh ECDH, kdf KDF) (string, error)

DecryptHexString decrypts ciphertext in hex form to plaintext by receiver private key

func Encrypt

func Encrypt(data []byte, pub *PublicKey, ecdh ECDH, kdf KDF) ([]byte, error)

Encrypt encrypts data using receiver public key

func EncryptStringToBase64 added in v0.2.0

func EncryptStringToBase64(plaintext string, pub *PublicKey, ecdh ECDH, kdf KDF) (string, error)

EncryptStringToBase64 encrypts plaintext to ciphertext in base64 form using receiver public key

func EncryptStringToHex added in v0.2.0

func EncryptStringToHex(plaintext string, pub *PublicKey, ecdh ECDH, kdf KDF) (string, error)

EncryptStringToHex encrypts plaintext to ciphertext in hex form using receiver public key

func EncryptToBase64 added in v0.3.1

func EncryptToBase64(data []byte, pub *PublicKey, ecdh ECDH, kdf KDF) (string, error)

EncryptToBase64 encrypts data to ciphertext in base64 form using receiver public key

func EncryptToHex added in v0.3.1

func EncryptToHex(data []byte, pub *PublicKey, ecdh ECDH, kdf KDF) (string, error)

EncryptToHex encrypts data to ciphertext in hex form using receiver public key

Types

type ECDH added in v0.2.0

type ECDH func(priv *PrivateKey, pub *PublicKey) (masterSecret []byte)

ECDH calculates a master secret from a private key & a public key. Its output will be passed to a KDF for deriving the encryption key.

type KDF added in v0.2.0

type KDF func(masterSecret []byte) (key []byte, err error)

KDF accepts a master secret & derives a encryption key

type Point added in v0.3.0

type Point struct {
	X, Y *big.Int
}

Point is a pont on the curve

type PrivateKey

type PrivateKey struct {
	Pub *PublicKey
	// contains filtered or unexported fields
}

PrivateKey ...

func GenerateKey

func GenerateKey(curve elliptic.Curve) (*PrivateKey, error)

GenerateKey generates a new elliptic curve key pair

func PrivateKeyFromBase64 added in v0.2.0

func PrivateKeyFromBase64(base64Key string, curve elliptic.Curve) (*PrivateKey, error)

PrivateKeyFromBase64 parses a private key from its base64 form

func PrivateKeyFromBytes

func PrivateKeyFromBytes(b []byte, curve elliptic.Curve) *PrivateKey

PrivateKeyFromBytes parses a private key from its raw bytes

func PrivateKeyFromHex

func PrivateKeyFromHex(hexKey string, curve elliptic.Curve) (*PrivateKey, error)

PrivateKeyFromHex parses a private key from its hex form

func PrivateKeyFromPEMBytes added in v0.3.3

func PrivateKeyFromPEMBytes(bytes []byte) (*PrivateKey, error)

PrivateKeyFromPEMBytes parses a private key from a PEM bytes

func PrivateKeyFromPEMFile added in v0.3.3

func PrivateKeyFromPEMFile(file string) (*PrivateKey, error)

PrivateKeyFromPEMFile parses a private key from a PEM file

func PrivateKeyFromPEMString added in v0.3.3

func PrivateKeyFromPEMString(str string) (*PrivateKey, error)

PrivateKeyFromPEMString parses a private key from a PEM string

func (*PrivateKey) Base64 added in v0.2.0

func (priv *PrivateKey) Base64() string

Base64 returns private key bytes in base64 form

func (*PrivateKey) Bytes

func (priv *PrivateKey) Bytes() []byte

Bytes returns private key raw bytes

func (*PrivateKey) Hex

func (priv *PrivateKey) Hex() string

Hex returns private key bytes in hex form

func (*PrivateKey) PEM added in v0.3.3

func (priv *PrivateKey) PEM() string

PEM returns private key in PEM form - string

func (*PrivateKey) SavePEMFile added in v0.3.3

func (priv *PrivateKey) SavePEMFile(file string) error

SavePEMFile saves private key to a PEM file

func (*PrivateKey) ToPEM added in v0.3.3

func (priv *PrivateKey) ToPEM() []byte

ToPEM returns private key in PEM form - bytes

type PublicKey

type PublicKey struct {
	*Point
	// contains filtered or unexported fields
}

PublicKey ...

func PublicKeyFromBase64 added in v0.2.0

func PublicKeyFromBase64(base64Key string, curve elliptic.Curve) (*PublicKey, error)

PublicKeyFromBase64 parses a public key from its base64 form

func PublicKeyFromBytes

func PublicKeyFromBytes(b []byte, curve elliptic.Curve) (*PublicKey, error)

PublicKeyFromBytes parses a public key from its uncompressed raw bytes

func PublicKeyFromHex

func PublicKeyFromHex(hexKey string, curve elliptic.Curve) (*PublicKey, error)

PublicKeyFromHex parses a public key from its hex form

func PublicKeyFromPEMBytes added in v0.3.3

func PublicKeyFromPEMBytes(bytes []byte) (*PublicKey, error)

PublicKeyFromPEMBytes parses a public key from its PEM form

func PublicKeyFromPEMFile added in v0.3.3

func PublicKeyFromPEMFile(path string) (*PublicKey, error)

PublicKeyFromPEMFile parses a public key from a PEM file

func PublicKeyFromPEMString added in v0.3.3

func PublicKeyFromPEMString(pemString string) (*PublicKey, error)

PublicKeyFromPEMString parses a public key from a PEM string

func (*PublicKey) Base64 added in v0.2.0

func (pub *PublicKey) Base64() string

Base64 returns public key bytes in base64 form

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

Bytes returns the public key to raw bytes in uncompressed format (Ox04|x|y) https://secg.org/sec1-v2.pdf#subsubsection.2.3.3

func (*PublicKey) Hex

func (pub *PublicKey) Hex() string

Hex returns public key bytes in hex form

func (*PublicKey) PEM added in v0.3.3

func (pub *PublicKey) PEM() string

PEM returns the public key in PEM format - string

func (*PublicKey) SaveToPEMFile added in v0.3.3

func (pub *PublicKey) SaveToPEMFile(path string) error

SaveToPEMFile saves the public key to a PEM file

func (*PublicKey) ScalarMult added in v0.3.0

func (pub *PublicKey) ScalarMult(priv *PrivateKey) *Point

ScalarMult returns publicKey * privateKey

func (*PublicKey) ToPEM added in v0.3.3

func (pub *PublicKey) ToPEM() []byte

ToPEM returns the public key in PEM format - bytes

Jump to

Keyboard shortcuts

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