Files
runesmith/generator.go
DaanSelen 9049c67cf2
Some checks failed
Cross-Compile Binaries / compile-windows (push) Failing after 41s
Cross-Compile Binaries / compile-linux (push) Successful in 3m29s
feat: new features - version 1.0.0
2026-01-06 16:07:49 +01:00

38 lines
800 B
Go

package main
import (
"crypto/rand"
"crypto/x509"
"software.sslmate.com/src/go-pkcs12"
)
const passChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?"
func generatePassword(n int) (string, error) {
bytes := make([]byte, n)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
for i, b := range bytes {
bytes[i] = passChars[int(b)%len(passChars)]
}
return string(bytes), nil
}
func generatePKCS12(pKey any, cert *x509.Certificate, caCerts []*x509.Certificate) (string, []byte, error) {
pfxPass, err := generatePassword(50)
if err != nil {
return "Failed to create password", nil, err
}
pfxData, err := pkcs12.Modern.Encode(pKey, cert, caCerts, pfxPass)
if err != nil {
return "", nil, err
} else {
return pfxPass, pfxData, nil
}
}