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";
/*
* Dados que serĂ£o assinados.
* */
String content = "Teste de assinatura PKCS#7";
/*
* Gera uma assinatura separada do arquivo.
*/
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.");
/*
* Gera uma co-assinatura.
* */
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();
}
}