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

馋奶兔 提交于 2019-12-03 22:17:18

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 .

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