crypto

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Database secret encryption using PEK without salt.
	// <remarks>Used until Windows Server 2000 Beta 2</remarks>
	SecretEncryptionType_DatabaseRC4 int = 0x10

	// Database secret encryption using PEK with salt.
	// <remarks>Used in Windows Server 2000 - Windows Server 2012 R2.</remarks>
	SecretEncryptionType_DatabaseRC4WithSalt int = 0x11

	// Replicated secret encryption using Session Key with salt.
	SecretEncryptionType_ReplicationRC4WithSalt int = 0x12

	// Database secret encryption using PEK and AES.
	// <remarks>Used since Windows Server 2016 TP4.</remarks>
	SecretEncryptionType_DatabaseAES int = 0x13
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PrivateKeyEncryptionType

type PrivateKeyEncryptionType int
const (
	NONE PrivateKeyEncryptionType = iota
	PasswordRC4
	PasswordRC2CBC
)

func (PrivateKeyEncryptionType) String

func (pket PrivateKeyEncryptionType) String() string

type SecretEncryptionType

type SecretEncryptionType struct {
	Value int

	// Internal
	RawBytes     []byte
	RawBytesSize uint32
}

func (*SecretEncryptionType) Marshal

func (set *SecretEncryptionType) Marshal() ([]byte, error)

Marshal returns the raw bytes of the SecretEncryptionType.

Returns: - A byte array containing the raw bytes of the SecretEncryptionType.

func (*SecretEncryptionType) String

func (set *SecretEncryptionType) String() string

String returns the string representation of the SecretEncryptionType.

func (*SecretEncryptionType) Unmarshal

func (set *SecretEncryptionType) Unmarshal(value []byte) (int, error)

Unmarshal parses the SecretEncryptionType from a byte array.

Parameters: - value: A byte array containing the SecretEncryptionType to be parsed.

type X509Certificate

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

X509Certificate represents an X.509 certificate along with its associated RSA private key and public key material.

Fields: - key: A pointer to an rsa.PrivateKey object representing the RSA private key associated with the certificate. - certificate: A pointer to an x509.Certificate object representing the X.509 certificate. - publicKey: An RSAKeyMaterial object representing the public key material of the certificate.

Methods: - NewX509Certificate: Creates a new X.509 certificate with the specified subject, key size, and validity period. - ExportPFX: Exports the certificate and private key to a PFX file with the specified password.

Note: The X509Certificate struct is used to manage X.509 certificates, including the generation of new certificates and the export of certificates and private keys to PFX files. The struct includes fields for the RSA private key, X.509 certificate, and public key material. The NewX509Certificate method is used to create a new certificate, and the ExportPFX method is used to export the certificate and private key to a PFX file.

func NewX509Certificate

func NewX509Certificate(subject string, keySize int, notBefore, notAfter time.Time) (*X509Certificate, error)

NewX509Certificate creates a new X.509 certificate with the specified subject, key size, and validity period.

Parameters: - subject: A string representing the common name (CN) of the certificate subject. - keySize: An integer specifying the size of the RSA key to be generated (e.g., 2048, 4096). - notBefore: A time.Time object representing the start of the certificate's validity period. - notAfter: A time.Time object representing the end of the certificate's validity period.

Returns: - A pointer to an X509Certificate object containing the generated certificate and associated RSA private key. - An error if the certificate generation fails.

Note: The function performs the following steps: 1. Generates a new RSA private key with the specified key size. 2. Creates a serial number for the certificate. 3. Constructs a certificate template with the specified subject, validity period, key usage, and extended key usage. 4. Creates a self-signed X.509 certificate using the generated RSA private key and certificate template. 5. Parses the generated certificate and returns an X509Certificate object containing the certificate and private key.

Example usage: cert, err := NewX509Certificate("example.com", 2048, time.Now(), time.Now().AddDate(1, 0, 0))

if err != nil {
    fmt.Printf("Error creating X509Certificate: %s\n", err)
}

func (*X509Certificate) ExportPFX

func (x *X509Certificate) ExportPFX(pathToFile, password string) error

ExportPFX exports the certificate and private key to a PFX file with the specified password.

Parameters: - pathToFile: A string representing the path to the file where the PFX will be exported. - password: A string representing the password for the PFX file.

Returns: - An error if the export fails, otherwise nil.

func (*X509Certificate) ExportRSAPrivateKeyBCrypt

func (x *X509Certificate) ExportRSAPrivateKeyBCrypt() (*keys.BCRYPT_RSA_PRIVATE_KEY, error)

ExportRSAPrivateKeyBCrypt exports the private key to a BCrypt file.

Parameters: - pathToFile: A string representing the path to the file where the private key will be exported.

Returns: - An error if the export fails, otherwise nil. - A pointer to a BCRYPT_RSA_PRIVATE_KEY object representing the private key.

func (*X509Certificate) ExportRSAPrivateKeyPEM

func (x *X509Certificate) ExportRSAPrivateKeyPEM(pathToFile string) error

ExportRSAPrivateKeyPEM exports the private key to a PEM file.

Parameters: - pathToFile: A string representing the path to the file where the private key will be exported.

Returns: - An error if the export fails, otherwise nil.

func (*X509Certificate) ExportRSAPublicKeyBCrypt

func (x *X509Certificate) ExportRSAPublicKeyBCrypt() (*keys.BCRYPT_RSA_PUBLIC_KEY, error)

ExportRSAPublicKeyBCrypt exports the public key to a BCrypt structure.

Parameters: - None

Returns: - A pointer to a BCRYPT_RSA_PUBLIC_KEY object representing the public key. - An error if the export fails, otherwise nil.

func (*X509Certificate) ExportRSAPublicKeyDER

func (x *X509Certificate) ExportRSAPublicKeyDER() ([]byte, error)

ExportRSAPublicKeyDER exports the public key to a DER file.

Parameters: - pathToFile: A string representing the path to the file where the public key will be exported.

Returns: - An error if the export fails, otherwise nil.

func (*X509Certificate) ExportRSAPublicKeyPEM

func (x *X509Certificate) ExportRSAPublicKeyPEM(pathToFile string) error

ExportRSAPublicKeyPEM exports the public key to a PEM file.

Parameters: - pathToFile: A string representing the path to the file where the public key will be exported.

Returns: - An error if the export fails, otherwise nil.

func (*X509Certificate) GetCertificate

func (x *X509Certificate) GetCertificate() *x509.Certificate

GetCertificate returns the certificate of the certificate.

Returns: - A pointer to an x509.Certificate object representing the certificate of the certificate.

func (*X509Certificate) GetRSAPrivateKey

func (x *X509Certificate) GetRSAPrivateKey() *rsa.PrivateKey

GetRSAPrivateKey returns the private key of the certificate.

Returns: - A pointer to an rsa.PrivateKey object representing the private key of the certificate.

func (*X509Certificate) GetRSAPublicKey

func (x *X509Certificate) GetRSAPublicKey() *rsa.PublicKey

GetRSAPublicKey returns the public key of the certificate.

Returns: - A pointer to an rsa.PublicKey object representing the public key of the certificate.

Jump to

Keyboard shortcuts

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