Mono-binarify for api server.

This commit is contained in:
Naoki Kosaka
2021-06-18 09:25:55 +09:00
parent 7894e78c3f
commit 73a1f2231c
30 changed files with 786 additions and 334 deletions

View File

@ -4,9 +4,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
)
func ReadPrivateKeyRSAfromPath(path string) (*rsa.PrivateKey, error) {
@ -21,29 +19,3 @@ func ReadPrivateKeyRSAfromPath(path string) (*rsa.PrivateKey, error) {
}
return priv, nil
}
func ReadPublicKeyRSAfromString(pemString string) (*rsa.PublicKey, error) {
pemByte := []byte(pemString)
decoded, _ := pem.Decode(pemByte)
defer func() {
recover()
}()
keyInterface, err := x509.ParsePKIXPublicKey(decoded.Bytes)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return nil, err
}
pub := keyInterface.(*rsa.PublicKey)
return pub, nil
}
func GeneratePublicKeyPEMString(publicKey *rsa.PublicKey) string {
publicKeyByte := x509.MarshalPKCS1PublicKey(publicKey)
publicKeyPem := pem.EncodeToMemory(
&pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: publicKeyByte,
},
)
return string(publicKeyPem)
}