use of codec.asn1.DEREncoder in project core by jcryptool.
the class ImportExportManager method exportKeyPair.
public void exportKeyPair(IPath path, PrivateKey key, Certificate[] chain, char[] password) {
PFX pfx;
X509Certificate[] x509Chain = convert(chain);
try {
if (x509Chain.length > 1) {
X509Certificate[] shortChain = new X509Certificate[x509Chain.length - 1];
for (int i = 1; i < chain.length; i++) {
shortChain[i - 1] = x509Chain[i];
}
pfx = new PFX(key, x509Chain[0], shortChain, password, null, null);
} else {
pfx = new PFX(key, x509Chain[0], null, password, null, null);
}
IFileStore fileStore = EFS.getStore(URIUtil.toURI(path));
OutputStream os = new BufferedOutputStream(fileStore.openOutputStream(EFS.APPEND, null));
DEREncoder encoder = new DEREncoder(os);
pfx.encode(encoder);
encoder.close();
os.close();
} catch (CertificateEncodingException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "CertificateEncodingException while creating a PFX", e, true);
} catch (GeneralSecurityException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "GeneralSecurityException while creating a PFX", e, true);
} catch (ASN1Exception e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "ASN1Exception while creating a PFX", e, true);
} catch (IOException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "IOException while creating a PFX", e, true);
} catch (CoreException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "CoreException while creating a PFX", e, true);
}
}
Aggregations