创建X509Certificate2时是否阻止文件创建? [英] Prevent file creation when X509Certificate2 is created?

查看:108
本文介绍了创建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时是否阻止文件创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆