org.restexpress.util.SslUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of RestExpress Show documentation
Show all versions of RestExpress Show documentation
Internet scale, high-performance RESTful Services in Java
package org.restexpress.util;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
public class SslUtil
{
public static SSLContext loadContext(String keyStore,
String filePassword, String keyPassword) throws Exception
{
FileInputStream fin = null;
try
{
KeyStore ks = KeyStore.getInstance("JKS");
fin = new FileInputStream(keyStore);
ks.load(fin, filePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, keyPassword.toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), null, null);
return context;
}
finally
{
if (null != fin)
{
try
{
fin.close();
}
catch (IOException e)
{
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy