forked from TrueCloudLab/lego
add crypto.go
This commit is contained in:
parent
728646c70e
commit
b04e5a4aac
1 changed files with 33 additions and 0 deletions
33
acme/crypto.go
Normal file
33
acme/crypto.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package acme
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/rsa"
|
||||||
|
"crypto/x509"
|
||||||
|
"crypto/x509/pkix"
|
||||||
|
"encoding/pem"
|
||||||
|
)
|
||||||
|
|
||||||
|
func generatePrivateKey(keyLength int) (*rsa.PrivateKey, error) {
|
||||||
|
return rsa.GenerateKey(rand.Reader, keyLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateCsr(privateKey *rsa.PrivateKey, domain string) ([]byte, error) {
|
||||||
|
template := x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{
|
||||||
|
CommonName: domain,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return x509.CreateCertificateRequest(rand.Reader, &template, privateKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pemEncode(data interface{}) []byte {
|
||||||
|
var pemBlock *pem.Block
|
||||||
|
switch key := data.(type) {
|
||||||
|
case *rsa.PrivateKey:
|
||||||
|
pemBlock = &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pem.EncodeToMemory(pemBlock)
|
||||||
|
}
|
Loading…
Reference in a new issue