Exemplo de assinatura PKCS#7.
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";
String content = "Teste de assinatura PKCS#7";
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("Assinatura PKCS#7 gerada com sucesso.");
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("Co-assinatura PKCS#7 gerada com sucesso.");
api.closeSession();
}
}