feat(init): First commit

This commit is contained in:
Thomas Maurice 2024-02-11 19:59:34 +01:00
commit f92368748a
Signed by: thomas
GPG key ID: 1D577F50583032A6
22 changed files with 1298 additions and 0 deletions

31
pkg/crypto/key.go Normal file
View file

@ -0,0 +1,31 @@
package crypto
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
)
func GenerateKeyPair(bytes int) (string, string, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, bytes)
if err != nil {
return "", "", err
}
err = privateKey.Validate()
if err != nil {
return "", "", err
}
privBlock := pem.Block{
Type: "PRIVATE KEY",
Headers: nil,
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
}
privateKeyPEM := pem.EncodeToMemory(&privBlock)
return string(privateKeyPEM), string(base64.StdEncoding.EncodeToString(x509.MarshalPKCS1PublicKey(&privateKey.PublicKey))), nil
}