crypto

package
v0.0.0-...-58f6e79 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptStringWithAES

func DecryptStringWithAES(encryptedText string, key []byte) (string, error)

DecryptStringWithAES takes an encrypted, base64-encoded string and a key and returns the plaintext form of the string.

func EncryptStringWithAES

func EncryptStringWithAES(plainText string, key []byte) (string, error)

EncryptStringWithAES takes a string and a key and returns the encrypted, base64-encoded form of the string.

func GenerateAESKey

func GenerateAESKey() (string, error)

GenerateAESKey generates a cryptographically random 32-byte key, returned as a base64-encoded string.

func GenerateRandomPassword

func GenerateRandomPassword(ctx context.Context, length int, lowerChar, upperChar, digitChar, specialChar bool) string

func PKCS7Pad

func PKCS7Pad(input []byte, blockSize int) []byte

PKCS7Pad will pad the input to a multiple of blocksize according to PKCS#7 standard.

func PKCS7Unpad

func PKCS7Unpad(input []byte) ([]byte, error)

PKCS7Unpad will remove the padding from input according to PKCS#7 standard.

func RandomNumber

func RandomNumber(max int) int

RandomNumber will generate a cryptographically secure random number in the range of [0, max).

func RandomString

func RandomString(strSize int) string

RandomString returns a string of the specified length consisting only of alphabetic characters.

Types

type CertInfo

type CertInfo struct {
	CAKey      string
	CACert     string
	ServerKey  string
	ServerCert string
	ClientKey  string
	ClientCert string
}

func MakeHTTPCertInfo

func MakeHTTPCertInfo(caCertName, serverCertName, clientCertName string) (*CertInfo, error)

MakeHTTPCertInfo generates a CA key and cert, then uses that key to sign two other keys and certs, one for a TLS server and one for a TLS client. None of the parameters are configurable...the serial numbers and principal names are hardcoded, the validity period is hardcoded to 1970-2070, and the algorithm and key size are hardcoded to 521-bit elliptic curve.

Jump to

Keyboard shortcuts

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