use of com.bluenimble.platform.crypto.SecureDocument 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()));
}
Aggregations