cert

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: BSD-3-Clause Imports: 9 Imported by: 1

README

Cert Package

Go Reference License

A simple TLS configuration generator using ECDSA keys and self-signed certificates for Go applications.

Features

  • Easy-to-use TLS configuration generator
  • Uses ECDSA keys with P-256 curve
  • Self-signed certificate generation
  • One-year validity period
  • Custom organization name
  • Automatic random serial number generation

Installation

go get github.com/NodePassProject/cert

Usage

Basic Usage
package main

import (
    "github.com/NodePassProject/cert"
    "log"
    "net/http"
)

func main() {
    // Create a new TLS configuration with organization name
    tlsConfig, err := cert.NewTLSConfig("My Application")
    if err != nil {
        log.Fatalf("Failed to create TLS config: %v", err)
    }
    
    // Create a new HTTP server with TLS
    server := &http.Server{
        Addr:      ":8443",
        TLSConfig: tlsConfig,
        Handler:   yourHandler(),
    }
    
    // Start the server with TLS
    log.Printf("Starting secure server on https://localhost:8443")
    log.Fatal(server.ListenAndServeTLS("", ""))
}

func yourHandler() http.Handler {
    // Your HTTP handler implementation
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Secure server is running!"))
    })
}
Advanced Configuration

The TLS configuration returned by NewTLSConfig is a standard *tls.Config object that can be further customized:

tlsConfig, err := cert.NewTLSConfig("My Application")
if err != nil {
    log.Fatalf("Failed to create TLS config: %v", err)
}

// Customize the TLS configuration
tlsConfig.MinVersion = tls.VersionTLS12
tlsConfig.CipherSuites = []uint16{
    tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
    tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
}

License

Copyright (c) 2025, NodePassProject. Licensed under the BSD 3-Clause License. See the LICENSE file for details.

Documentation

Overview

Package cert 提供了一个简单的TLS配置生成器,使用ECDSA密钥和自签名证书。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTLSConfig

func NewTLSConfig(name string) (*tls.Config, error)

NewTLSConfig 生成TLS配置

Types

This section is empty.

Jump to

Keyboard shortcuts

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