com.dyadicsec.provider.DYCryptoProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.dyadicsec.provider;
import com.unbound.client.Client;
import com.unbound.client.Partition;
import com.unbound.common.Log;
import com.unbound.provider.UBCryptoProvider;
import com.unbound.provider.UBKeyStoreEntry;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* Created by valery.osheter on 19-Apr-16.
*/
public final class DYCryptoProvider extends Provider
{
private final static String name = "DYADIC";
private final static double version = 1.0;
private final static String info = "DyadicSec EKM security provider";
public DYCryptoProvider()
{
this(null);
}
public DYCryptoProvider(String configArg)
{
super(name, version, info);
Log log = Log.func("DYCryptoProvider").log("configArg", configArg).end();
try
{
Partition partition = Client.getInstance().initProvider(configArg);
if (partition==null) return;
Service[] services = UBCryptoProvider.register(this, partition);
for (Service s : services) putService(s);
}
catch (Exception e) { log.failed(e); throw e; } finally { log.leave(); }
}
public Provider configure(String configArg)
{
return new DYCryptoProvider(configArg);
}
public static final class KeyEntry extends UBKeyStoreEntry
{
public KeyEntry(PrivateKey key, com.unbound.provider.KeyParameters kp) { super(key, kp); }
public KeyEntry(PublicKey key, com.unbound.provider.KeyParameters kp) { super(key, kp); }
public KeyEntry(PrivateKey key) { super(key); }
public KeyEntry(PublicKey key) { super(key); }
}
public X509Certificate SelfSign(java.security.PrivateKey key, String hashAlg, String subject, BigInteger serialNumber, int days)
throws CertificateException
{
Log log = Log.func("DYCryptoProvider.SelfSign").log("subject", subject).end();
try { return UBCryptoProvider.selfSign(key, hashAlg, subject, serialNumber, days); }
catch (Exception e) { log.failed(e); throw e; } finally { log.leave(); }
}
public static void initialize(String[] servers, KeyStore trusted) throws MalformedURLException, KeyStoreException, NoSuchAlgorithmException
{
Log log = Log.func("DYCryptoProvider.initialize").end();
try { Client.getInstance().initProviders(servers, trusted); }
catch (Exception e) { log.failed(e); throw e; } finally { log.leave(); }
}
public DYCryptoProvider(KeyStore pfx, String pfxPass)
{
super(name, version, info);
Log log = Log.func("DYCryptoProvider-pfx").end();
try
{
Partition partition = Client.getInstance().initProvider(pfx, pfxPass);
Service[] services = UBCryptoProvider.register(this, partition);
for (Service s : services) putService(s);
}
catch (Exception e) { log.failed(e); throw e; } finally { log.leave(); }
}
public static void allowPrivateKeyWithoutCertificate(boolean allow)
{
UBCryptoProvider.allowPrivateKeyWithoutCertificate(allow);
}
public static void allowPublicKey(boolean allow)
{
UBCryptoProvider.allowPublicKey(allow);
}
}