Lab 13: TLS & Crypto
Overview
Step 1: ECDSA Key Generation
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"fmt"
"os"
)
func generateECDSAKey() (*ecdsa.PrivateKey, error) {
// P-256 (secp256r1) — NIST curve, widely supported
return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
}
func savePrivateKey(key *ecdsa.PrivateKey, path string) error {
keyDER, err := x509.MarshalECPrivateKey(key)
if err != nil {
return err
}
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()
return pem.Encode(f, &pem.Block{Type: "EC PRIVATE KEY", Bytes: keyDER})
}
func main() {
key, err := generateECDSAKey()
if err != nil {
panic(err)
}
fmt.Printf("ECDSA key: curve=%s\n", key.Curve.Params().Name)
fmt.Printf("Public key X: %x\n", key.X.Bytes()[:8]) // first 8 bytes
}Step 2: Self-Signed Certificate
Step 3: mTLS Server and Client
Step 4: AES-256-GCM Encryption
Step 5: SHA-256 and HMAC
Step 6: bcrypt Password Hashing
Step 7: Complete Crypto Demo
Step 8: Capstone — mTLS Demo (In-Process)
Summary
Algorithm
Package
Use Case
Last updated
