@@ -46,12 +46,12 @@ public void ec() throws Exception {
4646 String encodedPublicKey = PEM .encode (keyPair .getPublic ());
4747 assertNotNull (encodedPublicKey );
4848 assertTrue (encodedPublicKey .startsWith (PEM .X509_PUBLIC_KEY_PREFIX ));
49- assertTrue (encodedPublicKey .endsWith (PEM .X509_PUBLIC_KEY_SUFFIX + " \n " ));
49+ assertTrue (encodedPublicKey .endsWith (PEM .X509_PUBLIC_KEY_SUFFIX ));
5050
5151 String encodedPrivateKey = PEM .encode (keyPair .getPrivate ());
5252 assertNotNull (encodedPrivateKey );
5353 assertTrue (encodedPrivateKey .startsWith (PEM .PKCS_8_PRIVATE_KEY_PREFIX ));
54- assertTrue (encodedPrivateKey .endsWith (PEM .PKCS_8_PRIVATE_KEY_SUFFIX + " \n " ));
54+ assertTrue (encodedPrivateKey .endsWith (PEM .PKCS_8_PRIVATE_KEY_SUFFIX ));
5555
5656 // Since we built our own key pair, the private key will not contain the public key
5757 PEM pem = PEM .decode (encodedPrivateKey );
@@ -69,8 +69,8 @@ public void ec() throws Exception {
6969 @ Test
7070 public void ec_backAndForth () throws Exception {
7171 // Start with openSSL PKCS#8 private key and X.509 public key
72- String expectedPrivate = new String (Files .readAllBytes (Paths .get ("src/test/resources/ec_private_prime256v1_p_256_openssl_pkcs8.pem" )));
73- String expectedPublic = new String (Files .readAllBytes (Paths .get ("src/test/resources/ec_public_prime256v1_p_256_openssl.pem" )));
72+ String expectedPrivate = new String (Files .readAllBytes (Paths .get ("src/test/resources/ec_private_prime256v1_p_256_openssl_pkcs8.pem" ))). trim () ;
73+ String expectedPublic = new String (Files .readAllBytes (Paths .get ("src/test/resources/ec_public_prime256v1_p_256_openssl.pem" ))). trim () ;
7474
7575 // Decode the private key to ensure we get both private and public keys out of the private PEM
7676 PEM pem = PEM .decode (expectedPrivate );
@@ -103,12 +103,12 @@ public void rsa() throws Exception {
103103 String encodedPublicKey = PEM .encode (keyPair .getPublic ());
104104 assertNotNull (encodedPublicKey );
105105 assertTrue (encodedPublicKey .startsWith (PEM .X509_PUBLIC_KEY_PREFIX ));
106- assertTrue (encodedPublicKey .endsWith (PEM .X509_PUBLIC_KEY_SUFFIX + " \n " ));
106+ assertTrue (encodedPublicKey .endsWith (PEM .X509_PUBLIC_KEY_SUFFIX ));
107107
108108 String encodedPrivateKey = PEM .encode (keyPair .getPrivate ());
109109 assertNotNull (encodedPrivateKey );
110110 assertTrue (encodedPrivateKey .startsWith (PEM .PKCS_8_PRIVATE_KEY_PREFIX ));
111- assertTrue (encodedPrivateKey .endsWith (PEM .PKCS_8_PRIVATE_KEY_SUFFIX + " \n " ));
111+ assertTrue (encodedPrivateKey .endsWith (PEM .PKCS_8_PRIVATE_KEY_SUFFIX ));
112112
113113 // Since the public RSA modulus and public exponent are always included in the private key, they should
114114 // be contained in the generated PEM
@@ -120,8 +120,8 @@ public void rsa() throws Exception {
120120 @ Test
121121 public void rsa_backAndForth_pkcs_1 () throws Exception {
122122 // Start externally created PKCS#1 private key and X.509 public key
123- String expectedPrivate_pkcs_1 = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_1_control.pem" )));
124- String expectedPrivate_pkcs_8 = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem" )));
123+ String expectedPrivate_pkcs_1 = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_1_control.pem" ))). trim () ;
124+ String expectedPrivate_pkcs_8 = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem" ))). trim () ;
125125 String expectedPublic = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_public_key_2048_x509_control.pem" )));
126126
127127 // Decode the private key to ensure we get both private and public keys out of the private PEM
@@ -146,14 +146,14 @@ public void rsa_backAndForth_pkcs_1() throws Exception {
146146
147147 // Re-encode the public key to PEM X.509 format and ensure it equals the original
148148 String encodedPublicKey = PEM .encode (pem .getPublicKey ());
149- assertEquals (encodedPublicKey , expectedPublic + " \n " );
149+ assertEquals (encodedPublicKey , expectedPublic );
150150 }
151151
152152 @ Test
153153 public void rsa_backAndForth_pkcs_8 () throws Exception {
154154 // Start externally created PKCS#1 private key and X.509 public key
155- String expectedPrivate = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem" )));
156- String expectedPublic = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_public_key_2048_x509_control.pem" )));
155+ String expectedPrivate = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_private_key_2048_pkcs_8_control.pem" ))). trim () ;
156+ String expectedPublic = new String (Files .readAllBytes (Paths .get ("src/test/resources/rsa_public_key_2048_x509_control.pem" ))). trim () ;
157157
158158 // Decode the private key to ensure we get both private and public keys out of the private PEM
159159 PEM pem = PEM .decode (expectedPrivate );
@@ -175,6 +175,6 @@ public void rsa_backAndForth_pkcs_8() throws Exception {
175175
176176 // Re-encode the public key to PEM X.509 format and ensure it equals the original
177177 String encodedPublicKey = PEM .encode (pem .getPublicKey ());
178- assertEquals (encodedPublicKey , expectedPublic + " \n " );
178+ assertEquals (encodedPublicKey , expectedPublic );
179179 }
180180}
0 commit comments