elgamalecc

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrivateKey = errors.New("go-cryptobin/elgamalecc: incorrect private key")
	ErrPublicKey  = errors.New("go-cryptobin/elgamalecc: incorrect public key")
)

Functions

func AddNamedCurve

func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)

func Decrypt

func Decrypt(priv *PrivateKey, C1x, C1y *big.Int, C2 *big.Int) (plain []byte, err error)

Decrypt with Elgamal

func DecryptASN1

func DecryptASN1(priv *PrivateKey, data []byte) ([]byte, error)

Decrypt asn.1 marshal data

func Encrypt

func Encrypt(random io.Reader, pub *PublicKey, data []byte) (C1x, C1y *big.Int, C2 *big.Int, err error)

Encrypt with Elgamal

func EncryptASN1

func EncryptASN1(random io.Reader, pub *PublicKey, data []byte) ([]byte, error)

Encrypted and return asn.1 data

func MarshalECPrivateKey

func MarshalECPrivateKey(key *PrivateKey) ([]byte, error)

MarshalECPrivateKey converts an EC private key to SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY". For a more flexible key format which is not EC specific, use MarshalPKCS8PrivateKey.

func MarshalPrivateKey

func MarshalPrivateKey(key *PrivateKey) ([]byte, error)

Marshal PrivateKey to der

func MarshalPublicKey

func MarshalPublicKey(pub *PublicKey) ([]byte, error)

Marshal PublicKey to der

func NamedCurveFromOid

func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve

func OidFromNamedCurve

func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool)

func PrivateKeyTo

func PrivateKeyTo(key *PrivateKey) []byte

output PrivateKey data

func PublicKeyTo

func PublicKeyTo(key *PublicKey) []byte

output PublicKey data

Types

type PrivateKey

type PrivateKey struct {
	PublicKey

	D *big.Int
}

bign PrivateKey

func GenerateKey

func GenerateKey(random io.Reader, c elliptic.Curve) (*PrivateKey, error)

Generate the PrivateKey

func NewPrivateKey

func NewPrivateKey(curve elliptic.Curve, k []byte) (*PrivateKey, error)

New a PrivateKey from privatekey data

func ParseECPrivateKey

func ParseECPrivateKey(der []byte) (*PrivateKey, error)

ParseECPrivateKey parses an EC private key in SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY".

func ParsePrivateKey

func ParsePrivateKey(derBytes []byte) (*PrivateKey, error)

Parse PrivateKey der

func (*PrivateKey) Decrypt

func (priv *PrivateKey) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)

Decrypt decrypts ciphertext with priv.

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether pub and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

type PublicKey

type PublicKey struct {
	elliptic.Curve

	X, Y *big.Int
}

bign PublicKey

func NewPublicKey

func NewPublicKey(curve elliptic.Curve, k []byte) (*PublicKey, error)

New a PublicKey from publicKey data

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error)

Parse PublicKey der

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and x have the same value.

Jump to

Keyboard shortcuts

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