Sign multiple pdf with itextsharp and token prompts for pin every time

吃可爱长大的小学妹 提交于 2020-01-12 10:55:10

问题


Hi I am trying to prevent multiple pin prompts for every pdf that needs to be signed.

I am using code from this example :

Pin is required when this part of code get process :

MakeSignature.SignDetached(appearance, pks, chain, crlList, ocspClient, tsaClient, estimatedSize,
subfilter);

Is there any way to memorize token pin and sing rest of pdfs without prompting for pin?


回答1:


Finally I found solution, this code does the trick :

...
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)pk.PrivateKey;

CspParameters cspp = new CspParameters();
cspp.KeyContainerName = rsa.CspKeyContainerInfo.KeyContainerName;
cspp.ProviderName = rsa.CspKeyContainerInfo.ProviderName;
// cspp.ProviderName = "Microsoft Smart Card Key Storage Provider";

cspp.ProviderType = rsa.CspKeyContainerInfo.ProviderType;

cspp.Flags = CspProviderFlags.NoPrompt;

RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider(cspp);

rsa.PersistKeyInCsp = true;
...
MakeSignature.SignDetached(...);

Creating CspParameters before signing, remebers the pin code. There is official documentacion on msdn .



来源:https://stackoverflow.com/questions/27523779/sign-multiple-pdf-with-itextsharp-and-token-prompts-for-pin-every-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!