use of com.bluenimble.platform.crypto.generator.impl.DefaultCertificatesManager in project serverless by bluenimble.
the class SignVerifyDocument method main.
public static void main(String[] args) throws StoreLoaderException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, SignerException, IOException {
String password = "beesphere";
String alias = "beesphere";
String p12 = "beesphere.p12";
final String cer = "beesphere.cer";
CertificatesManager cm = new DefaultCertificatesManager();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(CertificatesManager.KEY_PASSWORD, password);
KeyStore ks = cm.load(new FileInputStream(p12), properties);
PrivateKey key = (PrivateKey) ks.getKey(alias, password.toCharArray());
Signer signer = new DefaultSigner();
SecureDocument doc = new StringSecureDocument("a document to sign");
signer.sign(doc, key, new X509Certificate[] { ReadX509.read(new FileInputStream(cer)) });
System.out.println(new String(doc.getBytes()));
signer.verify(doc, new CertificateAcceptor() {
private static final long serialVersionUID = 8524753501741582177L;
@Override
public boolean accept(X509Certificate cert) throws SignerException {
try {
return cert.equals(ReadX509.read(new FileInputStream(cer)));
} catch (Throwable th) {
throw new SignerException(th, th.getMessage());
}
}
});
System.out.println(new String(doc.getBytes()));
}
use of com.bluenimble.platform.crypto.generator.impl.DefaultCertificatesManager in project serverless by bluenimble.
the class GenerateFullPKCS12KeyPair method main.
public static void main(String[] args) throws CertificatesManagerException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
String fileName = "files/testFull.p12";
// Create generator instance
CertificatesManager generator = new DefaultCertificatesManager();
// Properties
Map<String, Object> props = new HashMap<String, Object>();
props.put(CertificatesManager.COMMON_NAME, "bs");
props.put(CertificatesManager.ORGANIZATION_NAME, "bs");
props.put(CertificatesManager.ORGANIZATION_UNIT, "bs");
props.put(CertificatesManager.COUNTRY, "MA");
props.put(CertificatesManager.STATE, "MA");
props.put(CertificatesManager.LOCALITY_NAME, "Rabat");
props.put(CertificatesManager.STORE, "PKCS12");
props.put(CertificatesManager.KEY_SIZE, 1024);
props.put(CertificatesManager.KEY_ALGORITHM, "RSA");
props.put(CertificatesManager.SIGNATURE_ALGORITHM, "MD5withRSA");
props.put(CertificatesManager.EMAIL, "ait@beesphere.com");
props.put(CertificatesManager.KEY_PASSWORD, "beesphere");
// Generate keypair
OutputStream os = new FileOutputStream(fileName);
generator.generate(props, os);
os.close();
// Read keypair
System.out.println(ReadPKCS12.read(new FileInputStream(fileName), "beesphere", DefaultCertificatesManager.DEFAULT_ALIAS));
}
use of com.bluenimble.platform.crypto.generator.impl.DefaultCertificatesManager in project serverless by bluenimble.
the class GeneratePKCS12KeyPair method main.
public static void main(String[] args) throws CertificatesManagerException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
String fileName = "files/test.p12";
// Create generator instance
CertificatesManager generator = new DefaultCertificatesManager();
// Generate keypair
OutputStream os = new FileOutputStream(fileName);
generator.generate(new HashMap<String, Object>(), os);
os.close();
// Read keypair
System.out.println(ReadPKCS12.read(new FileInputStream(fileName), DefaultCertificatesManager.DUMMY_PASS, DefaultCertificatesManager.DEFAULT_ALIAS));
}
use of com.bluenimble.platform.crypto.generator.impl.DefaultCertificatesManager in project serverless by bluenimble.
the class ExportDERCertificate method main.
public static void main(String[] args) throws CertificateExportException, StoreLoaderException, IOException, CertificateException {
String storeFileName = "files/test.p12";
String certFileName = "files/test.cer";
Map<String, Object> EMPTY_MAP = new HashMap<String, Object>();
// Create generator instance
CertificatesManager manager = new DefaultCertificatesManager();
// Export certification DER format
OutputStream os = new FileOutputStream(certFileName);
manager.export(manager.load(new FileInputStream(storeFileName), EMPTY_MAP), EMPTY_MAP, CertificatesManager.ExportFormat.DER, os);
os.close();
// Read keypair
System.out.println(ReadX509.read(new FileInputStream(certFileName)));
}
use of com.bluenimble.platform.crypto.generator.impl.DefaultCertificatesManager in project serverless by bluenimble.
the class ExportPEMCertificate method main.
public static void main(String[] args) throws CertificateExportException, StoreLoaderException, IOException, CertificateException {
String storeFileName = "files/test.p12";
String certFileName = "files/test.pem";
Map<String, Object> EMPTY_MAP = new HashMap<String, Object>();
// Create generator instance
CertificatesManager manager = new DefaultCertificatesManager();
// Export certification PEM format
OutputStream os = new FileOutputStream(certFileName);
manager.export(manager.load(new FileInputStream(storeFileName), EMPTY_MAP), EMPTY_MAP, CertificatesManager.ExportFormat.PEM, os);
os.close();
}
Aggregations