English 中文(简体)
制度:非法性。 利用根基资源档案
原标题:System.ArgumentException: Illegal characters in path. using files from the embedded resources
  • 时间:2024-02-26 02:31:11
  •  标签:
  • c#

我试图打上资源档案,我把这一档案藏在资源中。 这是一份证书。 简言之,我试图打电话,然后才能安装证书;没有用户必须下载档案。 这里是我手法:

        public static void TESTNEWINSTALL()
    {
        string myString = System.Text.Encoding.UTF8.GetString(Properties.Resources.FiddlerRoot);
        X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadWrite);
        store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(myString)));
        store.Close();
        MessageBox.Show("Done");
    }

The Embedded Resource is called FiddlerRoot but it s actually a file named FiddlerRoot.cer. However I am getting an error code: Illegal characters in path on the line: store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(myString)));

我也附上了一张照片供作进一步解释。 我在这里做了什么错误?

https://i.stack.imgur.com/26aiF.png

问题回答

CreateFromCertFile expects a filename, not an actual certificate.

此外:

  • You are for some reason creating a second certificate from the first, for no apparent reason.
  • You are reading the certificate data as a string, which is not necessary, and in the case of DER encoding is counter-productive (it s not necessarily a valid string).
  • You are also missing various usings.
public static void TESTNEWINSTALL()
{
    var certData = Properties.Resources.FiddlerRoot;
    using X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
    store.Open(OpenFlags.ReadWrite);
    using var cert = new X509Certificate2(certData);
    store.Add(cert);
    store.Close();
    MessageBox.Show("Done");
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签