diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/util/X509Utilities.java b/eiam-common/src/main/java/cn/topiam/employee/common/util/X509Utilities.java index cda48814..4490f3fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/util/X509Utilities.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/util/X509Utilities.java @@ -46,10 +46,11 @@ import org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder; */ public class X509Utilities { - public static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----"; - public static final String END_CERT = "-----END CERTIFICATE-----"; - public static final String BEGIN_KEY = "-----BEGIN RSA PRIVATE KEY-----"; - public static final String END_KEY = "-----END RSA PRIVATE KEY-----"; + public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + public static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----" + LINE_SEPARATOR; + public static final String END_CERT = "-----END CERTIFICATE-----"; + public static final String BEGIN_KEY = "-----BEGIN RSA PRIVATE KEY-----" + LINE_SEPARATOR; + public static final String END_KEY = "-----END RSA PRIVATE KEY-----"; public static byte[] getDer(String combinedKeyAndCertPem, String begin, String end) { String[] tokens = combinedKeyAndCertPem.split(begin); @@ -65,7 +66,7 @@ public class X509Utilities { public static String keyCleanup(String pem) { return pem.replace(BEGIN_CERT, "").replace(END_CERT, "").replace(BEGIN_KEY, "") - .replace(END_KEY, "").replace("\n", "").trim().replace("\r",""); + .replace(END_KEY, "").replace("\n", "").trim(); } public static X509Certificate getCertificate(byte[] der) throws CertificateException { @@ -133,4 +134,4 @@ public class X509Utilities { return kp.getPublic(); } -} +} \ No newline at end of file