Mono-binarify for api server.
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user