fix: couldn't trasform ecc certificate to pfx format

This commit is contained in:
Fu Diwei
2025-01-18 07:09:41 +08:00
parent 6adcc61447
commit d28b89f03e
+19 -3
View File
@@ -2,6 +2,8 @@
import (
"bytes"
"crypto/ecdsa"
"crypto/rsa"
"encoding/pem"
"errors"
"time"
@@ -26,9 +28,23 @@ func TransformCertificateFromPEMToPFX(certPem string, privkeyPem string, pfxPass
return nil, err
}
privkey, err := ParsePKCS1PrivateKeyFromPEM(privkeyPem)
if err != nil {
return nil, err
var privkey interface{}
switch cert.PublicKey.(type) {
case *rsa.PublicKey:
{
privkey, err = ParsePKCS1PrivateKeyFromPEM(privkeyPem)
if err != nil {
return nil, err
}
}
case *ecdsa.PublicKey:
{
privkey, err = ParseECPrivateKeyFromPEM(privkeyPem)
if err != nil {
return nil, err
}
}
}
pfxData, err := pkcs12.LegacyRC2.Encode(privkey, cert, nil, pfxPassword)