crypto

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeEcdsaPrivateKeyFromPem

func DecodeEcdsaPrivateKeyFromPem(pemEncodedPrivKey []byte) (*ecdsa.PrivateKey, error)

DecodeEcdsaPrivateKeyFromPem decodes pem private key

func DecryptUsingSymmKey

func DecryptUsingSymmKey(encryptedMsg, privKey []byte) ([]byte, error)

DecryptUsingSymmKey Decrypts data using ChaCha2020 TODO: Give option to change encryption algo

func EncodeEcdsaPrivateKeyToPem

func EncodeEcdsaPrivateKeyToPem(privateKey *ecdsa.PrivateKey) ([]byte, []byte, error)

EncodeEcdsaPrivateKeyToPem encodes ecdsa private key to pem format

func EncryptUsingSymmKey

func EncryptUsingSymmKey(msg, privKey []byte) ([]byte, error)

EncryptUsingSymmKey Enrypts data using ChaCha2020 TODO: Give option to change encryption algo

func ExportRsaPrivateKeyAsPemStr

func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string

ExportRsaPrivateKeyAsPemStr exports the rsa priv key in pem format

func ExportRsaPrivateKeyToFile

func ExportRsaPrivateKeyToFile(fileName string, key *rsa.PrivateKey) error

ExportRsaPrivateKeyToFile exports the rsa priv key to a file

func ExportRsaPublicKeyAsPemStr

func ExportRsaPublicKeyAsPemStr(pubkey *rsa.PublicKey) string

ExportRsaPublicKeyAsPemStr exports the rsa pub key in pem format

func ExportRsaPublicKeyToFile

func ExportRsaPublicKeyToFile(fileName string, key *rsa.PublicKey) error

ExportRsaPublicKeyToFile exports the rsa pub key to a file

func GenerateEcdsaKeyPair

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

GenerateEcdsaKeyPair generates a pub/priv ecdsa key pair

func GenerateRsaKeyPair

func GenerateRsaKeyPair(bits int) (*rsa.PrivateKey, error)

GenerateRsaKeyPair generates a pub/priv rsa key pair

func GetHash

func GetHash(msg []byte) []byte

GetHash returns the hash of a message

func HMAC

func HMAC(message, key []byte, hashFunc func() hash.Hash) []byte

HMAC returns the hmac of the message and key

func ParseRsaPrivateKeyFromFile

func ParseRsaPrivateKeyFromFile(fileName string) (*rsa.PrivateKey, error)

ParseRsaPrivateKeyFromFile parses the priv key from the given file

func ParseRsaPrivateKeyFromPemStr

func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)

ParseRsaPrivateKeyFromPemStr parses the private key from the given pem string

func ParseRsaPublicKeyFromPemStr

func ParseRsaPublicKeyFromPemStr(pubPEM string) (*rsa.PublicKey, error)

ParseRsaPublicKeyFromPemStr parses the pub key from the given pem string

func Sign

func Sign(msg []byte, key *rsa.PrivateKey) (signature []byte, err error)

Sign returns a signature made by combining the message and the signers private key

func SignEcdsa

func SignEcdsa(msg []byte, key *ecdsa.PrivateKey) ([]byte, error)

SignEcdsa returns a signature made by combining the message and the signers private key using ecdsa

func ValidMAC

func ValidMAC(message, key, messageMAC []byte, hashFunc func() hash.Hash) bool

ValidMAC reports whether messageMAC is a valid HMAC tag for message.

func Verify

func Verify(msg []byte, sig []byte, pk *rsa.PublicKey) error

Verify checks if a message is signed by a given Public Key

func VerifyEcdsa

func VerifyEcdsa(msg []byte, sig []byte, pk *ecdsa.PublicKey) bool

VerifyEcdsa checks if a message is signed by a given public key using ecdsa

Types

type KeyStore

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

KeyStore is a as the name says a keystore which stores multiple privatekeys

func NewKeyStore

func NewKeyStore() *KeyStore

NewKeyStore Creates a new keystore

func (*KeyStore) AddKey

func (store *KeyStore) AddKey(keyName, pem string) error

AddKey Adds a private rsa key to the keystore

func (*KeyStore) AddKeyFromFile

func (store *KeyStore) AddKeyFromFile(keyName, fileName string) error

AddKeyFromFile Adds a private rsa key to the keystore from the file

func (*KeyStore) Key

func (store *KeyStore) Key(keyName string) (*rsa.PrivateKey, bool)

Key Gets the private key for the given identifier

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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