
com.sap.cloud.alert.notification.client.internal.KeyStoreUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clm-sl-alert-notification-client Show documentation
Show all versions of clm-sl-alert-notification-client Show documentation
Means for out-of-the-box events management in SAP Alert Notification service for SAP BTP service.
package com.sap.cloud.alert.notification.client.internal;
import com.sap.cloud.alert.notification.client.exceptions.ClientRequestException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.util.Base64;
import static java.nio.charset.StandardCharsets.UTF_8;
public class KeyStoreUtils {
public static KeyStore buildKeyStore(KeyStoreDetails keyStoreDetails) {
KeyStoreType keyStoreType = keyStoreDetails.getKeyStoreType();
try {
if (keyStoreType == KeyStoreType.PEM) {
return PemCertificateUtils.generateKeyStore(keyStoreDetails);
}
KeyStore keyStore = KeyStore.getInstance(keyStoreDetails.getKeyStoreType().getTechnicalName());
try (InputStream in = new ByteArrayInputStream(decodeKeyStoreContent(keyStoreDetails.getKeyStoreContent()))) {
keyStore.load(in, keyStoreDetails.getKeyStorePassword().toCharArray());
}
return keyStore;
} catch (Exception e) {
throw new ClientRequestException("Failed to generate keystore", e);
}
}
public static KeyStore buildKeyStore(String certificate, String privateKey) {
try {
return PemCertificateUtils.generateKeyStore(certificate, privateKey);
} catch (Exception e) {
throw new ClientRequestException("Failed to generate keystore", e);
}
}
private static byte[] decodeKeyStoreContent(String keyStoreContent) {
return Base64.getDecoder().decode(keyStoreContent);
}
protected static String decodeCertificateContent(String certificateContent) {
return new String(Base64.getDecoder().decode(certificateContent.getBytes(UTF_8)), UTF_8);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy