Smartcard CMS Decrypt

*爱你&永不变心* 提交于 2019-12-03 08:51:31

AFAIK BouncyCastleSharp works out-of-the-box only with the cryptographic keys that can be exposed into the host memory. However one must not forget that Bouncy Castle C# is a general purpose cryptographic library and if you are willing to do a little extra work on lower level APIs you can use it also with the keys that cannot be exposed in the host memory. Such keys are usually stored in specialized cryptographic hardware i.e. smartcards, HSMs, TPMs and usually can be accessed and used only via a specialized cryptographic API such as MS CryptoAPI (Windows only) and/or PKCS#11 API (multiplatform).

I have created an example application - Pkcs7SignatureGenerator - for CMS signature creation with Pkcs11Interop (which I am author of) and Bouncy Castle libraries. In this application Pkcs11Interop library performs signing operation via PKCS#11 API with the private key stored in the hardware device and Bouncy Castle library is responsible for construction of a CMS (PKCS#7) signature structure.

In your case you would need to use BouncyCastle library (low level APIs) to parse CMS structure and then use PKCS#11 library for low level decryption. This approach requires you to do more coding and to have much deeper understanding of CMS but it certainly can be done.

BTW few months ago I was evaluating available options for a closer integration of Pkcs11Interop and BouncyCastle libraries but I have found out that BouncyCastle key material handling APIs do not provide required level of abstraction and therefore such integration would require major rewrite of the library. That would break its backwards compatibility and IMO would not get accepted easily by the upstream developers. So I have decided not to proceed any further.

Hope this helps.

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