support base64 encoded pem blocks
@@ -217,9 +217,16 @@ func newParser(algo Algorithm, claims Claims) *jwt.Parser {
// must be given in PEM encoded format.
func parsePublicPEMKey(key []byte) (pub *rsa.PublicKey, err error) {
pemBlock, _ := pem.Decode(key)
+ if pemBlock == nil {
+ decKey, err := base64.StdEncoding.DecodeString(string(key))
+ if err != nil {
+ return nil, ErrorNotSupported
+ }
+ pemBlock, _ = pem.Decode(decKey)
if pemBlock == nil {
return nil, jwt.ErrKeyMustBePEMEncoded
}
+ }
pubKey, pubErr := x509.ParsePKCS1PublicKey(pemBlock.Bytes)
if pubErr != nil {
pkixKey, err := x509.ParsePKIXPublicKey(pemBlock.Bytes)
