Java API
HSM Dinamo
Loading...
Looking for...
No entries found
SignPKCS7.java

Example of PKCS#7 signature.

See Note on examples.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class SignPKCS7 {
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
api.openSession("127.0.0.1", "master", "12345678", false);
String keyId = "lab";
String certId = "lab_cert";
/*
* Data to be signed.
* */
String content = "PKCS#7 signature test";
/*
* Generates a separate signature for the file.
*/
byte[] signature = api.signPKCS7(keyId, certId, null, 0, content.getBytes());
Path sigFile = Paths.get("c:\\tmp\\signature.p7s");
try {
Files.write(sigFile, signature);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("PKCS#7 signature generated successfully.");
/*
* Generates a co-signature.
* */
byte[] cosignSignature = api.signPKCS7(keyId,
certId,
null,
TacNDJavaLib.TAC_MOD_CORE_P7_COSIGN |
TacNDJavaLib.TAC_MOD_CORE_P7_DETACHED,
signature);
Path cosignFile = Paths.get("c:\\tmp\\co_signature.p7s");
try {
Files.write(cosignFile, cosignSignature);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("PKCS#7 co-signature generated successfully.");
api.closeSession();
}
}