Strip out new lines from PEM encoded data

Fixes gh-72
This commit is contained in:
Dave Syer
2018-08-01 14:33:28 +01:00
parent 432edeecc1
commit 1a72f31772
2 changed files with 13 additions and 13 deletions

View File

@@ -15,15 +15,10 @@
*/
package org.springframework.cloud.cli.command.encrypt;
import static java.util.Arrays.asList;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.springframework.boot.cli.command.options.OptionHandler;
import org.springframework.boot.cli.util.Log;
import org.springframework.core.io.FileSystemResource;
@@ -32,6 +27,11 @@ import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
import org.springframework.util.StreamUtils;
import static java.util.Arrays.asList;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
class BaseEncryptOptionHandler extends OptionHandler {
private OptionSpec<String> keyOption;
@@ -104,7 +104,7 @@ class BaseEncryptOptionHandler extends OptionHandler {
catch (Exception e) {
// not a file
}
return new EncryptorFactory(verbose).create(value.trim());
return new EncryptorFactory(verbose).create(value.trim().replaceAll("\n", ""));
}
private String readFile(String filename) {

View File

@@ -15,18 +15,18 @@
*/
package org.springframework.cloud.cli.command.encrypt;
import static org.junit.Assert.assertEquals;
import java.nio.charset.Charset;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.cli.command.status.ExitStatus;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
import org.springframework.util.StreamUtils;
import static org.junit.Assert.assertEquals;
/**
* @author Dave Syer
*
@@ -42,11 +42,11 @@ public class DecryptCommandTests {
}
@Test
@Ignore //FIXME: 2.0.x
public void decryptsFromRsaKey() throws Exception {
RsaSecretEncryptor encryptor = new RsaSecretEncryptor(StreamUtils.copyToString(
new ClassPathResource("private.pem").getInputStream(),
Charset.forName("UTF-8")));
RsaSecretEncryptor encryptor = new RsaSecretEncryptor(StreamUtils
.copyToString(new ClassPathResource("private.pem").getInputStream(),
Charset.forName("UTF-8"))
.replaceAll("\n", ""));
String cipher = encryptor.encrypt("foo");
assertEquals(ExitStatus.OK,
command.run("-k", "@src/test/resources/private.pem", cipher));