Skip to content

Commit

Permalink
Merge pull request toorop#20 from jpbede/enhance/decode-pkcs8
Browse files Browse the repository at this point in the history
PKCS8 decode
  • Loading branch information
toorop committed Nov 3, 2020
2 parents 76378ae + c0072b1 commit e1cd1a0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dkim.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func NewSigOptions() SigOptions {
// Sign signs an email
func Sign(email *[]byte, options SigOptions) error {
var privateKey *rsa.PrivateKey
var err error

// PrivateKey
if len(options.PrivateKey) == 0 {
Expand All @@ -109,11 +110,17 @@ func Sign(email *[]byte, options SigOptions) error {
if d == nil {
return ErrCandNotParsePrivateKey
}
key, err := x509.ParsePKCS1PrivateKey(d.Bytes)
if err != nil {
return ErrCandNotParsePrivateKey

// try to parse it as PKCS1 otherwise try PKCS8
if key, err := x509.ParsePKCS1PrivateKey(d.Bytes); err != nil {
if key, err := x509.ParsePKCS8PrivateKey(d.Bytes); err != nil {
return ErrCandNotParsePrivateKey
} else {
privateKey = key.(*rsa.PrivateKey)
}
} else {
privateKey = key
}
privateKey = key

// Domain required
if options.Domain == "" {
Expand Down

0 comments on commit e1cd1a0

Please sign in to comment.