时间:2021-07-01 10:21:17 帮助过:81人阅读
public class CustomizableCrypto implements Crypto { /** * 构造 X509 式证书的工厂变量 */ private CertificateFactory certFact ; /** * 获取构造 X509 式证书的工厂变量(单例模式) * * @return 证书工厂变量 */ public synchronized CertificateFacto
publicclass CustomizableCrypto implements Crypto
{
/**
* 构造X509格式证书的工厂变量
*/
private CertificateFactory certFact;
/**
* 获取构造X509格式证书的工厂变量(单例模式)
*
* @return证书工厂变量
*/
publicsynchronizedCertificateFactory getCertificateFactory()
{
if (certFact == null)
{
try
{
certFact =CertificateFactory.getInstance("X.509");
}
catch(CertificateException e)
{
if (logger.isErrorEnable())
{
logger.error("Fail to get CertificateFactory");
}
}
returncertFact;
}
returncertFact;
}
public PrivateKeygetPrivateKey(String keyName, String passwrod)
{
PEMReader pemIn;
ByteArrayInputStreampemByteIn = new ByteArrayInputStream(getprivatekey(keyName));
pemIn = new PEMReader(newInputStreamReader(pemByteIn));
return ((KeyPair) pemIn.readObject()).getPrivate();
}
public X509Certificate[]getCertificates(String keyName)
{
X509Certificate[] certList= new X509Certificate[1];
// 从psql中取出证书并转换为X509格式证书
CertificateFactory cf = null;
X509Certificate cert = null;
cf = getCertificateFactory();
ByteArrayInputStream bais =new ByteArrayInputStream(getCertificate(keyName));
cert = (X509Certificate)cf.generateCertificate(bais);
certList[0] = cert;
return certList;
}
其他方法空实现....
}