Hi Francky,
That kind of operation is already supported by SUN's Java class X509Certificate i.e. it's not a JCAPI specific operation.
Here's an example of how to export the binary (ASN.1/DER) representation of an X.509 certificate:
import java.security.*;
import java.security.cert.*;
import java.io.*;
import java.util.*;
import com.pheox.jcapi.*;
public class ExportCert
{
static public void main(String[] args)
{
try {
export();
} catch(Throwable t) {
t.printStackTrace();
}
}
static private void export()
throws Exception
{
System.out.println("Export certificate to file cert.cer");
Security.addProvider(new JCAPIProvider());
KeyStore ks = KeyStore.getInstance("msks", "JCAPI");
ks.load(null, null);
//Get first certificate found.
Enumeration aliases = ks.aliases();
String alias = (String)aliases.nextElement();
if(alias == null)
throw new Exception("No certificate found.");
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
//Export/write certificate to file (X.509 ASN.1/DER).
FileOutputStream fos = new FileOutputStream("cert.cer");
try {
fos.write(cert.getEncoded());
} finally {
fos.close();
}
System.out.println("Done!");
}
}
Regards,
Tommy