如何在Docker容器内使用私钥和公共密钥读取SSL证书
我有一个使用dotnet 6构建的WebAPI应用程序。此应用程序使用SSL证书专用密钥对某些输入XML文件进行加密。 SSL证书停在主机上,该机器使用Docker-Compose安装在Docker图像上。要加密的XML还放在存在SSL证书的同一文件夹上。当我尝试从容器中读取此证书时,我会收到以下错误:
Type of Exception :Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException Exception Message: Object was not found. Exception Stack Trace: at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags).
但是,如果在没有Docker容器的情况下直接在主机计算机上运行相同的应用程序,则能够读取证书并加密文件。知道根本原因是什么?
I have a WebAPI application built using dotnet 6. This application encrypts some input xml files using SSL certificate private key. The SSL certificate rests on host machine which is mounted on docker image using docker-compose. Xmls to be encrypted also rests on the same folder where SSL certificate is present. When I try to read this certificate from the container, I get following error:
Type of Exception :Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException Exception Message: Object was not found. Exception Stack Trace: at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags).
However, if the same application is run on host machine directly without docker container it is able to read the certificate and encrypt the files. Any idea what could be the root cause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加用户:docker-compose.yml中的“ containerAdministrator”解决了问题
adding user: "ContainerAdministrator" in docker-compose.yml solved the issue