创建X509Certificate2时是否阻止文件创建?

编程入门 行业动态 更新时间:2024-10-26 16:29:44
本文介绍了创建X509Certificate2时是否阻止文件创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们在ASP.NET应用程序中创建一个X509Certificate2对象以进行定期的传出连接。每次创建这些证书之一时,都会在以下位置创建一个新文件:

We create a X509Certificate2 object in our ASP.NET app to make periodic outgoing connections. Every time one of these certificates is created a new file is created in:

C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys

C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys

该文件夹现在有400万个从未清除的文件。我试图删除Persist标志

That folder now has 4 million files that never get cleaned up. I've tried removing the Persist flag

新X509Certificate2(certBytes,p12Pwd, X509KeyStorageFlags.MachineKeySet);

new X509Certificate2(certBytes, p12Pwd, X509KeyStorageFlags.MachineKeySet);

//否X509KeyStorageFlags.PersistKeySet

//no X509KeyStorageFlags.PersistKeySet

但这无济于事-每次调用仍然获得2Kb文件。

but that doesn't help -- still get the 2Kb file on every call.

当我看到这个答案,但这是一台2008 R2服务器,临时文件不是0字节,因此情况似乎有所不同。

I got my hopes up when I saw this answer, but this is a 2008 R2 server, and the temp files are not 0 bytes, so it seems to be a different case.

我们如何使用一个X509Certificate2而不填满磁盘?

How can we use a X509Certificate2 without filling up the disk?

推荐答案

使用.NET 4.6 :

X509Certificate2实现了以开头的.NET的IDisposable接口。框架4.6;在.NET Framework的早期版本中,X509Certificate2类的不实现此接口,因此因此不存在Dispose方法。

X509Certificate2 implements the IDisposable interface starting with the .NET Framework 4.6; in previous versions of the .NET Framework, the X509Certificate2 class does not implement this interface, and therefore the Dispose method does not exist.

更多推荐

创建X509Certificate2时是否阻止文件创建?

本文发布于:2023-11-05 08:45:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!