|
@@ -100,6 +100,7 @@ func NewSigOptions() SigOptions {
|
100
|
100
|
// Sign signs an email
|
101
|
101
|
func Sign(email *[]byte, options SigOptions) error {
|
102
|
102
|
var privateKey *rsa.PrivateKey
|
|
103
|
+ var err error
|
103
|
104
|
|
104
|
105
|
// PrivateKey
|
105
|
106
|
if len(options.PrivateKey) == 0 {
|
|
@@ -109,11 +110,17 @@ func Sign(email *[]byte, options SigOptions) error {
|
109
|
110
|
if d == nil {
|
110
|
111
|
return ErrCandNotParsePrivateKey
|
111
|
112
|
}
|
112
|
|
- key, err := x509.ParsePKCS1PrivateKey(d.Bytes)
|
113
|
|
- if err != nil {
|
114
|
|
- return ErrCandNotParsePrivateKey
|
|
113
|
+
|
|
114
|
+ // try to parse it as PKCS1 otherwise try PKCS8
|
|
115
|
+ if key, err := x509.ParsePKCS1PrivateKey(d.Bytes); err != nil {
|
|
116
|
+ if key, err := x509.ParsePKCS8PrivateKey(d.Bytes); err != nil {
|
|
117
|
+ return ErrCandNotParsePrivateKey
|
|
118
|
+ } else {
|
|
119
|
+ privateKey = key.(*rsa.PrivateKey)
|
|
120
|
+ }
|
|
121
|
+ } else {
|
|
122
|
+ privateKey = key
|
115
|
123
|
}
|
116
|
|
- privateKey = key
|
117
|
124
|
|
118
|
125
|
// Domain required
|
119
|
126
|
if options.Domain == "" {
|