c3crypto

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

c3cypto

Various cryptographic functions

Documentation

Index

Constants

View Source
const (
	// EncryptionCipher ...
	EncryptionCipher = x509.PEMCipherAES256
	// PrivateKeyPEMType ...
	PrivateKeyPEMType = "ECDSA PRIVATE KEY"
	// PublicKeyPEMType ...
	PublicKeyPEMType = "ECDSA PUBLIC KEY"
)

Variables

View Source
var (
	// ErrNilPrivateKey ...
	ErrNilPrivateKey = errors.New("private key is nil")
	// ErrNilPublicKey ...
	ErrNilPublicKey = errors.New("public key is nil")
	// ErrNilData ...
	ErrNilData = errors.New("data is nil")
	// ErrNilSigParams ...
	ErrNilSigParams = errors.New("r and s params cannot be nil")
	// ErrInvalidPublicKey ...
	ErrInvalidPublicKey = errors.New("invalid public key")
	// ErrGeneratingECIESPublicKey ...
	ErrGeneratingECIESPublicKey = errors.New("could not generate ecies public key from ecda public key")
	// ErrGeneratingECIESPrivateKey ...
	ErrGeneratingECIESPrivateKey = errors.New("could not generate ecies private key from ecdsa private key")
	// ErrGeneratingECDSAPublicKey ...
	ErrGeneratingECDSAPublicKey = errors.New("could not generate ecdsa public key from ecdsa private key")
	// ErrNotECDSAPubKey ...
	ErrNotECDSAPubKey = errors.New("not an ecdsa public key")
	// Curve ...
	Curve = elliptic.P256()
)

Functions

func DecodeAddress

func DecodeAddress(address string) (*ecdsa.PublicKey, error)

DecodeAddress [for now] decodes public address hex to ECDSA public key. Public key are treated as public address at the moment.

func DecodePemToPrivateKey

func DecodePemToPrivateKey(block *pem.Block, password *string) (*ecdsa.PrivateKey, error)

DecodePemToPrivateKey ...

func DecodePemToPublicKey

func DecodePemToPublicKey(block *pem.Block, password *string) (*ecdsa.PublicKey, error)

DecodePemToPublicKey ...

func Decrypt

func Decrypt(priv *ecdsa.PrivateKey, data []byte) ([]byte, error)

Decrypt ...

func DeserializePrivateKey

func DeserializePrivateKey(privBytes []byte) (*ecdsa.PrivateKey, error)

DeserializePrivateKey ...

func DeserializePublicKey

func DeserializePublicKey(pubBytes []byte) (*ecdsa.PublicKey, error)

DeserializePublicKey ...

func EncodeAddress

func EncodeAddress(pub *ecdsa.PublicKey) (string, error)

EncodeAddress ...

func EncodePrivateKeyToPem

func EncodePrivateKeyToPem(priv *ecdsa.PrivateKey, password *string) (*pem.Block, error)

EncodePrivateKeyToPem ... note password is optional

func EncodePublicKeyToPem

func EncodePublicKeyToPem(pub *ecdsa.PublicKey, password *string) (*pem.Block, error)

EncodePublicKeyToPem ... note: password is optional

func Encrypt

func Encrypt(pub *ecdsa.PublicKey, data []byte) ([]byte, error)

Encrypt ...

func GetPublicKey

func GetPublicKey(priv *ecdsa.PrivateKey) (*ecdsa.PublicKey, error)

GetPublicKey ...

func NewKeyPair

func NewKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)

NewKeyPair ...

func NewPrivateKey

func NewPrivateKey() (*ecdsa.PrivateKey, error)

NewPrivateKey ...

func PublicKeyFromBytes

func PublicKeyFromBytes(pub []byte) (*ecdsa.PublicKey, error)

PublicKeyFromBytes ...

func PublicKeyToBytes

func PublicKeyToBytes(pub *ecdsa.PublicKey) ([]byte, error)

PublicKeyToBytes ...

func ReadKeyPairFromPem

func ReadKeyPairFromPem(fileName string, password *string) (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)

ReadKeyPairFromPem ...

func ReadPrivateKeyFromPem

func ReadPrivateKeyFromPem(fileName string, password *string) (*ecdsa.PrivateKey, error)

ReadPrivateKeyFromPem ...

func ReadPublicKeyFromPem

func ReadPublicKeyFromPem(fileName string, password *string) (*ecdsa.PublicKey, error)

ReadPublicKeyFromPem ...

func SerializePrivateKey

func SerializePrivateKey(priv *ecdsa.PrivateKey) ([]byte, error)

SerializePrivateKey ...

func SerializePublicKey

func SerializePublicKey(pub *ecdsa.PublicKey) ([]byte, error)

SerializePublicKey ...

func Sign

func Sign(priv *ecdsa.PrivateKey, data []byte) (*big.Int, *big.Int, error)

Sign ...

func Verify

func Verify(pub *ecdsa.PublicKey, data []byte, r, s *big.Int) (bool, error)

Verify ...

func WriteKeyPairToPem

func WriteKeyPairToPem(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, password *string, fileName string) error

WriteKeyPairToPem ...

func WritePrivateKeyToPemFile

func WritePrivateKeyToPemFile(priv *ecdsa.PrivateKey, password *string, fileName string) error

WritePrivateKeyToPemFile ...

func WritePublicKeyToPemFile

func WritePublicKeyToPemFile(pub *ecdsa.PublicKey, password *string, fileName string) error

WritePublicKeyToPemFile ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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