crypto

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Certificate

type Certificate struct {
	Cert string
	Key  string
}

type CryptoRegistry

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

func NewRegistry

func NewRegistry() *CryptoRegistry

NewRegistry creates a new instance of CryptoRegistry with an embedded Handler.

func (*CryptoRegistry) Bcrypt

func (ch *CryptoRegistry) Bcrypt(value string) (string, error)

Bcrypt generates a bcrypt hash from the given value string.

value - the string to be hashed. Returns the bcrypt hash as a string.

For an example of this function in a Go template, refer to Sprout Documentation: bcrypt.

func (*CryptoRegistry) BuildCustomCertificate

func (ch *CryptoRegistry) BuildCustomCertificate(b64cert string, b64key string) (Certificate, error)

BuildCustomCertificate builds a custom certificate from a base64 encoded certificate and private key.

b64cert - the base64 encoded certificate. b64key - the base64 encoded private key. Returns a certificate and an error.

For an example of this function in a Go template, refer to Sprout Documentation: buildCustomCert.

func (*CryptoRegistry) DecryptAES

func (ch *CryptoRegistry) DecryptAES(password string, crypt64 string) (string, error)

DecryptAES decrypts the given base64-encoded AES-encrypted string using the provided password.

Parameters:

  • password: the password to use for decryption
  • crypt64: the base64-encoded AES-encrypted string to be decrypted

Returns:

  • string: the decrypted text
  • error: an error if any occurred during the decryption process

For an example of this function in a Go template, refer to Sprout Documentation: decryptAES.

func (*CryptoRegistry) DerivePassword

func (ch *CryptoRegistry) DerivePassword(counter uint32, passwordType, password, user, site string) (string, error)

DerivePassword derives a password based on the given counter, password type, password, user, and site.

counter - the counter value used in the password derivation process. passwordType - the type of password to derive. password - the password used in the derivation process. user - the user string used in the derivation process. site - the site string used in the derivation process. Returns the derived password as a string.

For an example of this function in a Go template, refer to Sprout Documentation: derivePassword.

func (*CryptoRegistry) EncryptAES

func (ch *CryptoRegistry) EncryptAES(password string, plaintext string) (string, error)

EncryptAES encrypts a plaintext string using AES encryption with a given password.

Parameters:

  • password: the password to use for encryption
  • plaintext: the text to be encrypted

Returns:

  • string: the encrypted text as a base64-encoded string
  • error: an error if any occurred during the encryption process

For an example of this function in a Go template, refer to Sprout Documentation: encryptAES.

func (*CryptoRegistry) GenerateCertificateAuthority

func (ch *CryptoRegistry) GenerateCertificateAuthority(
	cn string,
	daysValid int,
) (Certificate, error)

GenerateCertificateAuthority generates a certificate authority using the provided common name and validity period.

Parameters:

  • cn: the common name for the certificate authority
  • daysValid: the number of days the certificate authority is valid for

Returns:

  • Certificate: the generated certificate authority
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genCA.

func (*CryptoRegistry) GenerateCertificateAuthorityWithPEMKey

func (ch *CryptoRegistry) GenerateCertificateAuthorityWithPEMKey(
	cn string,
	daysValid int,
	privPEM string,
) (Certificate, error)

GenerateCertificateAuthorityWithPEMKey generates a certificate authority using the provided common name, validity period, and private key in PEM format.

Parameters:

  • cn: the common name for the certificate authority
  • daysValid: the number of days the certificate authority is valid for
  • privPEM: the private key in PEM format

Returns:

  • Certificate: the generated certificate authority
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genCAWithKey.

func (*CryptoRegistry) GeneratePrivateKey

func (ch *CryptoRegistry) GeneratePrivateKey(typ string) (string, error)

GeneratePrivateKey generates a private key of the specified type.

typ - the type of private key to generate (e.g., "rsa", "dsa", "ecdsa", "ed25519"). Returns the generated private key as a string.

For an example of this function in a Go template, refer to Sprout Documentation: genPrivateKey.

func (*CryptoRegistry) GenerateSelfSignedCertificate

func (ch *CryptoRegistry) GenerateSelfSignedCertificate(
	cn string,
	ips []any,
	alternateDNS []any,
	daysValid int,
) (Certificate, error)

GenerateSelfSignedCertificate generates a new, self-signed x509 certificate using a 2048-bit RSA private key.

Parameters:

  • cn: the common name for the certificate
  • ips: a list of IP addresses
  • alternateDNS: a list of alternate DNS names
  • daysValid: the number of days the certificate is valid for

Returns:

  • Certificate: the generated certificate
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genSelfSignedCert.

func (*CryptoRegistry) GenerateSelfSignedCertificateWithPEMKey

func (ch *CryptoRegistry) GenerateSelfSignedCertificateWithPEMKey(
	cn string,
	ips []any,
	alternateDNS []any,
	daysValid int,
	privPEM string,
) (Certificate, error)

GenerateSelfSignedCertificateWithPEMKey generates a new, self-signed x509 certificate using a given private key in PEM format.

Parameters:

  • cn: the common name for the certificate
  • ips: a list of IP addresses
  • alternateDNS: a list of alternate DNS names
  • daysValid: the number of days the certificate is valid for
  • privPEM: the private key in PEM format

Returns:

  • Certificate: the generated certificate
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genSelfSignedCertWithKey.

func (*CryptoRegistry) GenerateSignedCertificate

func (ch *CryptoRegistry) GenerateSignedCertificate(
	cn string,
	ips []any,
	alternateDNS []any,
	daysValid int,
	ca Certificate,
) (Certificate, error)

GenerateSignedCertificate generates a new, signed x509 certificate using a given CA certificate.

Parameters:

  • cn: the common name for the certificate
  • ips: a list of IP addresses
  • alternateDNS: a list of alternate DNS names
  • daysValid: the number of days the certificate is valid for
  • ca: the CA certificate to sign with

Returns:

  • Certificate: the generated certificate
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genSignedCert.

func (*CryptoRegistry) GenerateSignedCertificateWithPEMKey

func (ch *CryptoRegistry) GenerateSignedCertificateWithPEMKey(
	cn string,
	ips []any,
	alternateDNS []any,
	daysValid int,
	ca Certificate,
	privPEM string,
) (Certificate, error)

GenerateSignedCertificateWithPEMKey generates a new, signed x509 certificate using a given CA certificate and a private key in PEM format.

Parameters:

  • cn: the common name for the certificate
  • ips: a list of IP addresses
  • alternateDNS: a list of alternate DNS names
  • daysValid: the number of days the certificate is valid for
  • ca: the CA certificate to sign with
  • privPEM: the private key in PEM format

Returns:

  • Certificate: the generated certificate
  • error: an error if any occurred during the generation process

For an example of this function in a Go template, refer to Sprout Documentation: genSignedCertWithKey.

func (*CryptoRegistry) Htpasswd

func (ch *CryptoRegistry) Htpasswd(username string, password string) (string, error)

Htpasswd generates an Htpasswd hash from the given username and password strings.

username - the username string for the Htpasswd hash. password - the password string for the Htpasswd hash. Returns the generated Htpasswd hash as a string.

For an example of this function in a Go template, refer to Sprout Documentation: htpasswd.

func (*CryptoRegistry) LinkHandler

func (ch *CryptoRegistry) LinkHandler(fh sprout.Handler) error

func (*CryptoRegistry) RegisterFunctions

func (ch *CryptoRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error

RegisterFunctions adds all crypto-related functions to the provided registry.

func (*CryptoRegistry) UID added in v1.0.0

func (ch *CryptoRegistry) UID() string

UID returns the unique identifier of the crypto handler.

type DSAKeyFormat

type DSAKeyFormat struct {
	Version       int
	P, Q, G, Y, X *big.Int
}

DSAKeyFormat stores the format for DSA keys. Used by pemBlockForKey

Jump to

Keyboard shortcuts

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