Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64 cannot be decoded to KeyStore with Java client #1296

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ static byte[] decodeBase64String(final String certificateContent) {
}

static String encodeAsBase64String(final byte[] bytes) {
return Base64.getMimeEncoder().encodeToString(bytes);
return Base64.getEncoder().encodeToString(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.security.cert.CertificateEncodingException;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.github.nagyesta.lowkeyvault.service.certificate.impl.CertContentType.PEM;
Expand Down Expand Up @@ -468,7 +469,8 @@ void testEncodeAsBase64StringShouldProduceTheExpectedBase64String(final byte[] i
final String actual = CertContentType.encodeAsBase64String(input);

//then
Assertions.assertEquals(expected, actual);
final String expectedWithoutLineBreaks = expected.replaceAll(Pattern.quote("\r\n"), "");
Assertions.assertEquals(expectedWithoutLineBreaks, actual);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Objects;

import static java.util.Base64.getDecoder;
import static java.util.Base64.getMimeDecoder;

public class CertificateStepDefAssertion extends CommonAssertions {
Expand Down Expand Up @@ -305,7 +306,7 @@ private X509Certificate getX509Certificate(final CertificateContentType contentT
final CertificateFactory fact = CertificateFactory.getInstance("X.509");
certificate = (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(encodedCertificate));
} else {
final byte[] bytes = getMimeDecoder().decode(value);
final byte[] bytes = getDecoder().decode(value);
final KeyStore keyStore = getKeyStore(bytes, DEFAULT_PASSWORD);
final String alias = findAlias(keyStore);
certificate = (X509Certificate) keyStore.getCertificate(alias);
Expand Down
Loading