Register /
Login
|
Desktop view
|
public static void main(String[] args)
{
try
{
Security.addProvider(new JCAPIProvider());
KeyStore ks = KeyStore.getInstance("msks", "JCAPI");
ks.load(null, null);
String alias = null;
RSAPrivateKey privateKey = null;
// Force JCAPI to export private keys.
JCAPIProperties.getInstance().setPrivateKeyExportable(true);
System.out.println("Trying to find an exportable RSA private key.");
// Get first available RSA private key.
for (java.util.Enumeration e = ks.aliases(); e.hasMoreElements();)
{
alias = (String) e.nextElement();
if (ks.isKeyEntry(alias))
{
privateKey = (RSAPrivateKey) ks.getKey(alias, null);
getCRLFromCertificate(ks.getCertificate(alias));
ks.getCertificateChain(alias);
}
break;
}
}
catch (Throwable t)
{
System.err.println("Example program failed.");
t.printStackTrace();
}
}
private static void getCRLFromCertificate(Certificate c) throws Exception
{
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bais = new ByteArrayInputStream(c.getEncoded());
cf.generateCertificate(bais);
Collection<? extends CRL> generatedCRL = cf.generateCRLs(bais);
bais.close();
// why this is always 0 ?!?!?!
System.out.println(generatedCRL.size());
}