-
Notifications
You must be signed in to change notification settings - Fork 1
Examples of using it
Jaan Murumets edited this page Jul 3, 2018
·
9 revisions
Here is a example of using Digidoc4J Smart-ID adapter with DigiDoc4J
First we configure the Smart-ID client:
// Client setup. Note that these values are demo environment specific.
SmartIdClient client = new SmartIdClient();
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
client.setRelyingPartyName("DEMO");
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v1/");
Then we create a SmartIdSignatureToken
instance:
NationalIdentity identity = new NationalIdentity("EE", "31111111111"); // identity of the signer
SmartIdSignatureToken smartIdSignatureToken = new SmartIdSignatureToken(client, identity);
Now we can use the SmartIdSignatureToken
instance along with DigiDoc4J to create and sign a BDOC container:
Create a container with a text file to be signed
Container container = ContainerBuilder.
aContainer().
withDataFile("testFiles/legal_contract_1.txt", "text/plain").
build();
// Get the signer's certificate
X509Certificate signingCert = smartIdSignatureToken.getCertificate()
// Get the data to be signed by the user
DataToSign dataToSign = SignatureBuilder.
aSignature(container).
withSigningCertificate(signingCert).
withSignatureDigestAlgorithm(DigestAlgorithm.SHA256).
buildDataToSign();
// Data to sign contains the digest that should be signed
byte[] digestToSign = dataToSign.getDigestToSign();
// Calculate the Smart-ID verification code to display on the web page or e-service
String verificationCode = VerificationCodeCalculator.calculate(digestToSign);
// Sign the digest
byte[] signatureValue = smartIdSignatureToken.signDigest(DigestAlgorithm.SHA256, digestToSign);
// Finalize the signature with OCSP response and timestamp (or timemark)
Signature signature = dataToSign.finalize(signatureValue);
// Add signature to the container
container.addSignature(signature);
For testing in demo environment TEST TSL must be used:
https://github.com/open-eid/digidoc4j/wiki/Using-test-TSL-lists