mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-20 16:21:45 +00:00
refactor: extend huaweicloud cdn sdk
This commit is contained in:
31
internal/pkg/utils/x509/converter.go
Normal file
31
internal/pkg/utils/x509/converter.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user