crypto

package
v0.0.0-...-270f78c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Zlib Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrivateKeyPemHeader represents the header that is appended to the PEM file when
	// storing the private key.
	PrivateKeyPemHeader = "EC PRIVATE KEY"
	// PublicKeyPemHeader represents the header that is appended to the PEM file when
	// storing the public key.
	PublicKeyPemHeader = "ECDSA PUBLIC KEY"
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(input io.Reader, passphrase []byte) (io.Reader, error)

AesDecrypt reads from input, decrypts with AES-256 and returns the reader to a read decrypted content from. passphrase is used to generate an encryption key.

func AesEncrypt

func AesEncrypt(input io.Reader, output io.Writer, passphrase []byte) error

AesEncrypt reads from input, encrypts with AES-256 and writes to the output. passphrase is used to generate an encryption key.

func CreateServerTLSConfiguration

func CreateServerTLSConfiguration() *tls.Config

CreateServerTLSConfiguration creates a basic tls.Config to be used by servers with recommended TLS settings

func CreateTLSConfigurationFromBytes

func CreateTLSConfigurationFromBytes(caCert, cert, key []byte, skipClientVerification, skipServerVerification bool) (*tls.Config, error)

CreateTLSConfigurationFromBytes initializes a tls.Config using a CA certificate, a certificate and a key loaded from memory.

func CreateTLSConfigurationFromDisk

func CreateTLSConfigurationFromDisk(caCertPath, certPath, keyPath string, skipServerVerification bool) (*tls.Config, error)

CreateTLSConfigurationFromDisk initializes a tls.Config using a CA certificate, a certificate and a key loaded from disk.

Types

type ECDSAService

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

ECDSAService is a service used to create digital signatures when communicating with an agent based environment(endpoint). It will automatically generates a key pair using ECDSA or can also reuse an existing ECDSA key pair.

func NewECDSAService

func NewECDSAService(secret string) *ECDSAService

NewECDSAService returns a pointer to a ECDSAService. An optional secret can be specified

func (*ECDSAService) CreateSignature

func (service *ECDSAService) CreateSignature(message string) (string, error)

CreateSignature creates a digital signature. It automatically hash a specific message using MD5 and creates a signature from that hash. If a secret is associated to the service, it will be used instead of the specified message. It then encodes the generated signature in base64.

func (*ECDSAService) EncodedPublicKey

func (service *ECDSAService) EncodedPublicKey() string

EncodedPublicKey returns the encoded version of the public that can be used to be shared with other services. It's the hexadecimal encoding of the public key content.

func (*ECDSAService) GenerateKeyPair

func (service *ECDSAService) GenerateKeyPair() ([]byte, []byte, error)

GenerateKeyPair will create a new key pair using ECDSA.

func (*ECDSAService) PEMHeaders

func (service *ECDSAService) PEMHeaders() (string, string)

PEMHeaders returns the ECDSA PEM headers.

func (*ECDSAService) ParseKeyPair

func (service *ECDSAService) ParseKeyPair(private, public []byte) error

ParseKeyPair parses existing private/public key pair content and associate the parsed keys to the service.

type Service

type Service struct{}

Service represents a service for encrypting/hashing data.

func (*Service) CompareHashAndData

func (*Service) CompareHashAndData(hash string, data string) error

CompareHashAndData compares a hash to clear data and returns an error if the comparison fails.

func (*Service) Hash

func (*Service) Hash(data string) (string, error)

Hash hashes a string using the bcrypt algorithm

Jump to

Keyboard shortcuts

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