@@ -279,20 +279,32 @@ with `cdoc2-lib` verify that you can access id-card with [DigiDoc4](https://gith
279279 Path destDir = Paths . get(" /tmp" );
280280 Integer slot = 0 ;
281281 String alias = " Isikutuvastus" ;
282- DecryptionKeyMaterial dkm = DecryptionKeyMaterial . fromKeyPair(
283- Pkcs11Tools . loadFromPKCS11Interactively(
284- " /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so " , // pkcs11 driver location, differs on different platforms
285- slot,
286- alias
287- )
282+
283+ // load keys by asking pin code interactively
284+ KeyPair keyPair = Pkcs11Tools . loadFromPKCS11Interactively(
285+ " /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so " , // pkcs11 driver location, differs on different platforms
286+ slot,
287+ alias
288288 );
289289
290+ // or load keys with a given pin code
291+ char [] pin;
292+ KeyPair keyPair = Pkcs11Tools . loadFromPKCS11WithPin(
293+ " /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so" , // pkcs11 driver location, differs on different platforms
294+ slot,
295+ new PasswordProtection (pin),
296+ alias
297+ );
298+
299+ DecryptionKeyMaterial dkm = DecryptionKeyMaterial . fromKeyPair(keyPair);
300+
290301 List<String > extractedFiles = new CDocDecrypter ()
291- .withCDoc(cdoc2FileToDecrypt. toFile())
292- .withRecipient(dkm)
293- .withDestinationDirectory(destDir. toFile())
294- .decrypt();
302+ .withCDoc(cdoc2FileToDecrypt. toFile())
303+ .withRecipient(dkm)
304+ .withDestinationDirectory(destDir. toFile())
305+ .decrypt();
295306```
307+
296308` /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so ` is location of OpenSC pkcs11 driver library. Some info
297309on setting up pcks11 on Ubuntu can be found in [ pkcs11.README] ( https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-lib/pkcs11.README )
298310
@@ -379,8 +391,6 @@ Similar to previous example, to decrypt cdoc2 with server recipient,
379391[ cdoc2-capsule-server] ( https://github.com/open-eid/cdoc2-capsule-server ) client needs to be configured.
380392
381393``` java
382-
383-
384394Path cdoc2FileToDecrypt = Paths . get(" /tmp/second.cdoc2" );
385395Path destDir = Paths . get(" /tmp" );
386396Integer slot = 0 ;
0 commit comments