cryptowrapper

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cryptowrapper contains several cryptographic algorithms like AES, RSA, ECDH, HMAC, HKDF and PBKDF2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(key []byte, input []byte) ([]byte, error)

AESCBCDecrypt performs a AES decryption in CBC mode

func AESCBCDecryptWithMAC

func AESCBCDecryptWithMAC(key []byte, input []byte) ([]byte, error)

AESCBCDecryptWithMAC performs a AES dencryption in CBC mode with a MAC authentication

func AESCBCEncrypt

func AESCBCEncrypt(key []byte, input []byte) ([]byte, error)

AESCBCEncrypt performs a AES encryption in CBC mode

func AESCBCEncryptWithMAC

func AESCBCEncryptWithMAC(key []byte, input []byte) ([]byte, error)

AESCBCEncryptWithMAC performs a AES encryption in CBC mode with a MAC authentication

func BytesToUUIDFormat

func BytesToUUIDFormat(bytes []byte) string

BytesToUUIDFormat converts a 16 bytes to UUID format

func DeriveKey

func DeriveKey(hash func() hash.Hash, weakKey []byte, salt []byte, info []byte, keySize int) ([]byte, error)

DeriveKey derives two cryptographically strong secret keys from the weak key. salt and info can be nil. salt is recommended to be hash-length sized random info is recommended to independent from the weak key. keySize is the desired size for the derived key, its up to yourself to split it as multiple keys for usage.

func GenUUID

func GenUUID() string

GenUUID generates UUID

func GenUUIDAlt

func GenUUIDAlt() string

GenUUID generates UUID

func GenerateECDHKeyPair

func GenerateECDHKeyPair(rand io.Reader) (crypto.PrivateKey, crypto.PublicKey, error)

GenerateECDHKeyPair generates the ECDH key pair

func GenerateECDHSharedSecret

func GenerateECDHSharedSecret(privKey crypto.PrivateKey, pubKey crypto.PublicKey) ([]byte, error)

GenerateECDHSharedSecret calculates a common secret using the private key and public key

func GenerateRSAKey

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

GenerateRSAKey generates the RSA private key

func HMACSHA256

func HMACSHA256(key []byte, messages ...[]byte) []byte

HMACSHA256 generates the HMAC for a message given a key.

func MD5UUIDFormat

func MD5UUIDFormat(input ...[]byte) string

MD5UUIDFormat gets the MD5 hash of the input content and convert to UUID Format

func MarshalECDHPublicKey

func MarshalECDHPublicKey(p crypto.PublicKey) []byte

MarshalECDHPublicKey marshals the public key into byte array

func MarshalPrivateKey

func MarshalPrivateKey(priv *rsa.PrivateKey) ([]byte, error)

MarshalPrivateKey marshals private key into ANS.1 DER bytes (PKSC#1 scheme)

func MarshalPublicKey

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

MarshalPublicKey marshals public key into ANS.1 DER bytes (PKSC#1 scheme)

func PBKDF2HMACSHA256

func PBKDF2HMACSHA256(password, salt []byte, iter, keyLen int) []byte

PBKDF2HMACSHA256 derives a key for a given password

func RSADecrypt

func RSADecrypt(priv *rsa.PrivateKey, ciphertext []byte, label []byte) ([]byte, error)

RSADecrypt decrypts the given cipher text with the private key

func RSAEncrypt

func RSAEncrypt(pub *rsa.PublicKey, msg []byte, label []byte) ([]byte, error)

RSAEncrypt encrypts the given message with the public key

func RSASign

func RSASign(priv *rsa.PrivateKey, message []byte) ([]byte, error)

RSASign signs the given message with the private key.

func RSAVerify

func RSAVerify(pub *rsa.PublicKey, message []byte, signiture []byte) error

RSAVerify verifies the given message with the public key

func RandBigInt

func RandBigInt(bits int) *big.Int

RandBigInt generates and return a bigInt 'bits' bits in length

func RandBytes

func RandBytes(n int) []byte

RandBytes returns n bytes of cryptographically strong random bytes.

func UnMarshalPrivateKey

func UnMarshalPrivateKey(der []byte) (*rsa.PrivateKey, error)

UnMarshalPrivateKey unmarshals ANS.1 DER bytes back to private key

func UnMarshalPublicKey

func UnMarshalPublicKey(der []byte) (pubKey *rsa.PublicKey, err error)

UnMarshalPublicKey unmarshals ANS.1 DER bytes back to public key

func UnmarshalECDHPublicKey

func UnmarshalECDHPublicKey(data []byte) (crypto.PublicKey, bool)

UnmarshalECDHPublicKey unmarshals byte array into public key

func ValidateUUID

func ValidateUUID(UUID string, sanitize ...bool) (string, error)

Validates UUID

Types

This section is empty.

Jump to

Keyboard shortcuts

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