29 lines
685 B
Go
29 lines
685 B
Go
package utils
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
func FormatPEMPrivateKey(privateKeyStr string) []byte {
|
|
const pemHeader = "-----BEGIN RSA PRIVATE KEY-----"
|
|
const pemFooter = "-----END RSA PRIVATE KEY-----"
|
|
|
|
return buildKey(pemHeader, privateKeyStr, pemFooter)
|
|
}
|
|
|
|
func FormatPEMPublicKey(publicKeyStr string) []byte {
|
|
const pemHeader = "-----BEGIN PUBLIC KEY-----"
|
|
const pemFooter = "-----END PUBLIC KEY-----"
|
|
|
|
return buildKey(pemHeader, publicKeyStr, pemFooter)
|
|
}
|
|
|
|
func buildKey(pemHeader, keyStr, pemFooter string) []byte {
|
|
var lines []string
|
|
lines = append(lines, pemHeader)
|
|
lines = append(lines, keyStr)
|
|
lines = append(lines, pemFooter)
|
|
|
|
return []byte(strings.Join(lines, "\n"))
|
|
}
|