aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2021-11-10 22:27:57 -0800
committerMike Crute <mike@crute.us>2021-11-10 22:27:57 -0800
commit4a1bc8a259a83ff83c6f9d82a387d96569b2d346 (patch)
tree9ef6ac43e8232c4faed4622896134c5628a825e9 /crypto
parent8c5b1d33cc3d4af0b7c0e0fc37a90ef80ba25fe5 (diff)
downloadgolib-4a1bc8a259a83ff83c6f9d82a387d96569b2d346.tar.bz2
golib-4a1bc8a259a83ff83c6f9d82a387d96569b2d346.tar.xz
golib-4a1bc8a259a83ff83c6f9d82a387d96569b2d346.zip
Import crypto utilsv0.2.0
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ecdsa/ecdsa.go11
-rw-r--r--crypto/x509/csr.go28
2 files changed, 39 insertions, 0 deletions
diff --git a/crypto/ecdsa/ecdsa.go b/crypto/ecdsa/ecdsa.go
new file mode 100644
index 0000000..3793663
--- /dev/null
+++ b/crypto/ecdsa/ecdsa.go
@@ -0,0 +1,11 @@
1package ecdsa
2
3import (
4 "crypto/ecdsa"
5 "crypto/elliptic"
6 "crypto/rand"
7)
8
9func GenerateECPrivateKey() (*ecdsa.PrivateKey, error) {
10 return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
11}
diff --git a/crypto/x509/csr.go b/crypto/x509/csr.go
new file mode 100644
index 0000000..76ea809
--- /dev/null
+++ b/crypto/x509/csr.go
@@ -0,0 +1,28 @@
1package x509
2
3import (
4 "crypto/rand"
5 "crypto/rsa"
6 "crypto/x509"
7 "crypto/x509/pkix"
8)
9
10const defaultRSAKeyStrength = 4096
11
12func GenerateRSAKeyCSR(domains ...string) ([]byte, *rsa.PrivateKey, error) {
13 ckey, err := rsa.GenerateKey(rand.Reader, defaultRSAKeyStrength)
14 if err != nil {
15 return nil, nil, err
16 }
17
18 csr, err := x509.CreateCertificateRequest(rand.Reader, &x509.CertificateRequest{
19 Subject: pkix.Name{CommonName: domains[0]},
20 DNSNames: domains,
21 ExtraExtensions: []pkix.Extension{},
22 }, ckey)
23 if err != nil {
24 return nil, nil, err
25 }
26
27 return csr, ckey, nil
28}