mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-22 04:09:58 +00:00
fix: couldn't trasform ecc certificate to pfx format
This commit is contained in:
parent
6adcc61447
commit
d28b89f03e
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/rsa"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
@ -26,9 +28,23 @@ func TransformCertificateFromPEMToPFX(certPem string, privkeyPem string, pfxPass
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
privkey, err := ParsePKCS1PrivateKeyFromPEM(privkeyPem)
|
var privkey interface{}
|
||||||
if err != nil {
|
switch cert.PublicKey.(type) {
|
||||||
return nil, err
|
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)
|
pfxData, err := pkcs12.LegacyRC2.Encode(privkey, cert, nil, pfxPassword)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user