Strip out new lines from PEM encoded data
Fixes gh-72
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user