mirror of
https://github.com/usual2970/certimate.git
synced 2025-09-02 06:21:47 +00:00
.github
.vscode
docker
internal
applicant
deployer
domain
domains
notify
pkg
core
utils
cast
fs
maps
x509
common.go
converter.go
parser.go
transformer.go
vendors
repository
rest
routes
utils
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
usage.gif
32 lines
652 B
Go
32 lines
652 B
Go
package x509
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
|
|
xerrors "github.com/pkg/errors"
|
|
)
|
|
|
|
// 将 ecdsa.PrivateKey 对象转换为 PEM 编码的字符串。
|
|
//
|
|
// 入参:
|
|
// - privkey: ecdsa.PrivateKey 对象。
|
|
//
|
|
// 出参:
|
|
// - privkeyPem: 私钥 PEM 内容。
|
|
// - err: 错误。
|
|
func ConvertECPrivateKeyToPEM(privkey *ecdsa.PrivateKey) (privkeyPem string, err error) {
|
|
data, err := x509.MarshalECPrivateKey(privkey)
|
|
if err != nil {
|
|
return "", xerrors.Wrap(err, "failed to marshal EC private key")
|
|
}
|
|
|
|
block := &pem.Block{
|
|
Type: "EC PRIVATE KEY",
|
|
Bytes: data,
|
|
}
|
|
|
|
return string(pem.EncodeToMemory(block)), nil
|
|
}
|