From f0ccaf01aca260a30db2fde05d309d7922a75522 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 28 Jun 2023 12:30:00 +0000 Subject: [PATCH] Remove obsolete code --- .../context/encrypt/EncryptorFactory.java | 44 +------------------ 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/encrypt/EncryptorFactory.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/encrypt/EncryptorFactory.java index 71bf521c..7ad230d0 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/encrypt/EncryptorFactory.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/encrypt/EncryptorFactory.java @@ -16,18 +16,6 @@ package org.springframework.cloud.context.encrypt; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.regex.Pattern; - -import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import org.bouncycastle.openssl.MiscPEMGenerator; -import org.bouncycastle.openssl.PEMKeyPair; -import org.bouncycastle.openssl.PEMParser; -import org.bouncycastle.util.io.pem.PemObjectGenerator; -import org.bouncycastle.util.io.pem.PemWriter; - import org.springframework.security.crypto.encrypt.Encryptors; import org.springframework.security.crypto.encrypt.TextEncryptor; import org.springframework.security.rsa.crypto.RsaSecretEncryptor; @@ -38,8 +26,6 @@ import org.springframework.security.rsa.crypto.RsaSecretEncryptor; */ public class EncryptorFactory { - private static final Pattern NEWLINE_ESCAPE_PATTERN = Pattern.compile("\\r|\\n"); - private String salt = "deadbeef"; public EncryptorFactory() { @@ -53,15 +39,7 @@ public class EncryptorFactory { TextEncryptor encryptor; if (data.contains("RSA PRIVATE KEY")) { - - try { - String normalizedPemData = normalizePem(data); - encryptor = new RsaSecretEncryptor(NEWLINE_ESCAPE_PATTERN.matcher(normalizedPemData).replaceAll("")); - } - catch (IllegalArgumentException e) { - throw new KeyFormatException(e); - } - + encryptor = new RsaSecretEncryptor(data); } else if (data.startsWith("ssh-rsa") || data.contains("RSA PUBLIC KEY")) { throw new KeyFormatException(); @@ -73,24 +51,4 @@ public class EncryptorFactory { return encryptor; } - private String normalizePem(String data) { - PEMKeyPair pemKeyPair = null; - try (PEMParser pemParser = new PEMParser(new StringReader(data))) { - pemKeyPair = (PEMKeyPair) pemParser.readObject(); - PrivateKeyInfo privateKeyInfo = pemKeyPair.getPrivateKeyInfo(); - - StringWriter textWriter = new StringWriter(); - try (PemWriter pemWriter = new PemWriter(textWriter)) { - PemObjectGenerator pemObjectGenerator = new MiscPEMGenerator(privateKeyInfo); - - pemWriter.writeObject(pemObjectGenerator); - pemWriter.flush(); - return textWriter.toString(); - } - } - catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); - } - } - }