-
Notifications
You must be signed in to change notification settings - Fork 6
Examples of how to use it
Andres Voll edited this page Sep 19, 2018
·
16 revisions
File dataFile = new File("/path/to/file"); // file to be encrypted
InputStream authCertificateInputStream = new FileInputStream("/path/to/recipient/certificate");
CDOCBuilder.defaultVersion() // or .version("1.1")
.withDataFile(dataFile) // this can be chained successively for encryption of multiple files
.withRecipient(authCertificateInputStream) // this can be chained successively for multiple recipients
.buildToFile(new File("path/to/cdoc/destination"));
File dataFile = new File("/path/to/file"); // file to be encrypted
InputStream authCertificateInputStream = new FileInputStream("/path/to/recipient/certificate");
CDOCBuilder.version("1.0")
.withDataFile(dataFile) // this can be chained successively for encryption of multiple files
.withRecipient(authCertificateInputStream) // this can be chained successively for multiple recipients
.buildToFile(new File("path/to/cdoc/destination"));
Note CDOC 1.0 works only for recipients owning RSA key pair. It is recommended to use CDOC 1.1, because it works out-of-the-box without the knowledge of the recipient's key pair algorithm.
Token token = new PKCS12Token(new FileInputStream("/path/to/p12/keystore"), "keystore password");
File cdoc = new File("/path/to/cdoc");
List<File> decryptedFiles = new CDOCDecrypter()
.withToken(token)
.withCDOC(cdoc)
.decrypt(new File("path/to/directory/where/decrypted/file(s)/will/be/placed"));
PKCS11TokenParams params = new PKCS11TokenParams("/path/to/pkcs11/driver", "your PIN1".toCharArray(), 0);
Token token = new PKCS11Token(params);
File cdoc = new File("/path/to/cdoc");
List<File> decryptedFiles = new CDOCDecrypter()
.withToken(token)
.withCDOC(cdoc)
.decrypt(new File("path/to/directory/where/decrypted/file(s)/will/be/placed"));
Note Using PKCS#11 requires installing OpenSC (or other) smart card/hardware token library on the machine. Once installed the PKCS#11 driver path should be specified as the input (e.g. "/usr/local/lib/onepin-opensc-pkcs11.so" for OpenSC installation on UNIX systems)