private

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeECDSA    = "EC PRIVATE KEY"
	TypeRSAPKCS1 = "RSA PRIVATE KEY"
	TypeRSAPKCS8 = "PRIVATE KEY"
	TypeAES      = "AES KEY"
)

PEM Block types

Variables

View Source
var (
	// ErrECDSADecodePEM defines error of PEM decoding for ECDSA key
	ErrECDSADecodePEM = errors.New("failed to decode PEM block containing ECDSA private key")
	// ErrECDSAVerifyFalse defines error if signature is not valid for given message
	ErrECDSAVerifyFalse = errors.New("signature is not valid for given message")
	// ErrECDSANotDefined defines error if ECDSA private key is not defined
	ErrECDSANotDefined = errors.New("ECDSA private key is not defined")

	// ErrRSADecodePEM defines error of PEM decoding for RSA key
	ErrRSADecodePEM = errors.New("failed to decode PEM block containing RSA private key")
	// ErrRSAUnknown defines error for unknown type of RSA key
	ErrRSAUnknown = errors.New("unknown type of RSA private key")
	// ErrRSANotDefined defines error if RSA private key is not defined
	ErrRSANotDefined = errors.New("RSA private key is not defined")

	// ErrAESDecodePEM defines error of PEM decoding for AES key
	ErrAESDecodePEM = errors.New("failed to decode PEM block containing AES key")
	// ErrAESNotDefined defines error if AES key is not defined
	ErrAESNotDefined = errors.New("AES key is not defined")
)

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements private crypto provider

func New

func New(ecdsaKey *ecdsa.PrivateKey, rsaKey *rsa.PrivateKey, aesKey []byte) *Provider

New creates a new crypto provider initialized by ECDSA, RSA private keys and AES key

func (Provider) DecryptAES

func (p Provider) DecryptAES(ctx context.Context, ciphertext []byte) ([]byte, error)

DecryptAES will attempt to decrypt a given ciphertext with an AES-256 key

func (Provider) DecryptRSA

func (p Provider) DecryptRSA(ctx context.Context, ciphertext []byte) ([]byte, error)

DecryptRSA will attempt to decrypt a given ciphertext with an RSA 2048 private key

func (Provider) EncryptAES

func (p Provider) EncryptAES(ctx context.Context, plaintext []byte) ([]byte, error)

EncryptAES will encrypt a plaintext using an AES-256 key

func (Provider) EncryptRSA

func (p Provider) EncryptRSA(ctx context.Context, plaintext []byte) ([]byte, error)

EncryptRSA will encrypt a plaintext message using an RSA 2048 public key plaintext message length is maximum 240 bytes (2048 bits minus padding: 11 bytes for PKCS#1 v1.5 padding)

func (*Provider) RegisterKeyAES

func (p *Provider) RegisterKeyAES(data []byte) error

RegisterKeyAES decodes and adds AES key from specified PEM block

func (*Provider) RegisterPrivateKeyECDSA

func (p *Provider) RegisterPrivateKeyECDSA(data []byte) error

RegisterPrivateKeyECDSA decodes and register ECDSA private key from specified PEM block

func (*Provider) RegisterPrivateKeyRSA

func (p *Provider) RegisterPrivateKeyRSA(data []byte) error

RegisterPrivateKeyRSA decodes and register RSA private key from specified PEM block

func (Provider) SignECDSA

func (p Provider) SignECDSA(ctx context.Context, plaintext []byte) ([]byte, error)

SignECDSA will sign a plaintext message using an ECDSA P384 asymmetric private key

func (Provider) VerifyECDSA

func (p Provider) VerifyECDSA(ctx context.Context, signature, plaintext []byte) error

VerifyECDSA will verify that an ECDSA P384 signature is valid for a given plaintext message

Jump to

Keyboard shortcuts

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