You were right. After I removed the provider and added again, it worked.

Thank you very much for your attention and kindness.

On 2020/06/22 15:41:39, Tilman Hausherr <thaush...@t-online.de> wrote: 
> I looked at my own implementation from years ago and there are 2 
> differences, that may or may not be relevant.
> 
> 1. I check if the provider name exists and remove it if it does, before 
> addProvider.
> 
> 2. I pass an input stream to SunPKCS11.
> 
> All this on jdk8. It is different on jdk9 and higher.
> 
> Tilman
> 
> 
> 
> --- Original-Nachricht ---
> Von: Gustavo Delgado
> Betreff: Re: Sign a PDF using USB Token - PKCS#11
> Datum: 21.06.2020, 1:38 Uhr
> An: users@pdfbox.apache.org
> 
> 
> 
> 
> @font-face { font-family: telegrotesk-medium_normal; src: 
> url("file:///android_asset/fonts/telegrotesk_normal.ttf");}html,body { 
> font-family: "telegrotesk-medium_normal"; font-size: medium; color: 
> #4b4b4b; width: 100%;}
> 
> I'm sorry about the missing code, I should've clarified that I'm using the 
> following example from the svn repository:
> 
> https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
> 
> Here's the complete stack trace, which I also added to the gist for a clear 
> view:
> https://gist.github.com/benywolf42/f5784671301478dd3e2cf803eb6ef8d5
> 
> 20:28:22.821 [main] DEBUG org.apache.pdfbox.cos.COSStream - Create 
> InputStream called without data being written before to stream.
> java.io.IOException: org.bouncycastle.operator.OperatorCreationException: 
> cannot create signer: No installed provider supports this key: 
> sun.security.pkcs11.P11Key$P11PrivateKey
> at 
> app.devir.docsigner.lib.CreateSignatureBase.sign(CreateSignatureBase.java:155)
> CreateSignatureBase.java:155
> at 
> org.apache.pdfbox.pdfwriter.COSWriter.doWriteSignature(COSWriter.java:734)
> at 
> org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1145)
> at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:385)
> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1378)
> at 
> org.apache.pdfbox.pdmodel.PDDocument.saveIncremental(PDDocument.java:967)
> at 
> app.devir.docsigner.lib.CreateSignature.signDetached(CreateSignature.java:157)
> CreateSignature.java:157
> at 
> app.devir.docsigner.lib.CreateSignature.signDetached(CreateSignature.java:113)
> CreateSignature.java:113
> at 
> app.devir.docsigner.lib.CreateSignature.initialize(CreateSignature.java:184)
> CreateSignature.java:184
> at app.devir.docsigner.Application.main(Application.java:20)
> Application.java:20
> Caused by: org.bouncycastle.operator.OperatorCreationException: cannot 
> create signer: No installed provider supports this key: 
> sun.security.pkcs11.P11Key$P11PrivateKey
> at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.build(Unknown 
> Source)
> at 
> app.devir.docsigner.lib.CreateSignatureBase.sign(CreateSignatureBase.java:141)
> CreateSignatureBase.java:141
> ... 9 more
> Caused by: java.security.InvalidKeyException: No installed provider 
> supports this key: sun.security.pkcs11.P11Key$P11PrivateKey
> at java.security.Signature$Delegate.chooseProvider(Signature.java:1138)
> Signature.java:1138
> at java.security.Signature$Delegate.engineInitSign(Signature.java:1179)
> Signature.java:1179
> at java.security.Signature.initSign(Signature.java:530)
> Signature.java:530
> ... 11 more
> 
> On 2020/06/20 05:20:15, Tilman Hausherr <thaush...@t-online.de> wrote:
> > Hi,
> >
> > Please post more of the stack trace. It is unclear what throws the
> > exception. And the code in the gist does not create a signer thus
> > something is missing. Did you use the code from the source code download
> > in the current version?
> >
> > see also
> > 
> https://stackoverflow.com/questions/23665092/how-to-get-keystore-from-usb-token-in-java
> >
> >
> >
> > Tilman
> >
> > Am 20.06.2020 um 05:44 schrieb Gustavo Delgado:
> > > Hello everyone! I hope you're all doing well.
> > >
> > > I'm struggling to digitally sign a pdf document for more time then I 
> would like and any help here is appreciated.
> > >
> > > I'm using a USB Token (StarSign Crypto USB Token S) and the proprietary 
> .dll available to load the keystore.
> > > I can get the available info from the token, but whenever I try to sign 
> a pdf using the <CreateSignature> class, I get the following exception:
> > >
> > > <<org.bouncycastle.operator.OperatorCreationException: cannot create 
> signer: No installed provider supports this key: 
> sun.security.pkcs11.P11Key$P11PrivateKey>>
> > >
> > > I've done some research but I couldn't find any resource to overcome 
> this problem using PDF Box, which is the library I'd like to use because of 
> its license.
> > >
> > > If can be of any help, I'm also posting the code I've used:
> > >
> > > https://gist.github.com/benywolf42/f5784671301478dd3e2cf803eb6ef8d5
> > >
> > > Thanks in advance and be safe!
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> > > For additional commands, e-mail: users-h...@pdfbox.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> > For additional commands, e-mail: users-h...@pdfbox.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> For additional commands, e-mail: users-h...@pdfbox.apache.org
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> Gesendet mit der Telekom Mail App
> <https://kommunikationsdienste.t-online.de/redirects/email_app_android_sendmail_footer>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to