diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 409ceb444ddba4ef805c5ac625c6199d2085d82c..931faacd7f069eac3cb94e1b7f4f344f778b577d 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1456,7 +1456,9 @@ class SimpleSAML_Utilities {
 
 		if (array_key_exists($prefix . 'certData', $metadata)) {
 			/* Full certificate data available from metadata. */
-			$ret['certData'] = $metadata[$prefix . 'certData'];
+			$certData = $metadata[$prefix . 'certData'];
+			$certData = str_replace(array("\r", "\n", "\t", ' '), '', $certData);
+			$ret['certData'] = $certData;
 
 			/* Recreate PEM-encoded certificate. */
 			$ret['PEM'] = "-----BEGIN CERTIFICATE-----\n" .