如何在.NET中导入使用sn.exe生成的.snk文件?

发布于 2024-09-06 11:28:49 字数 230 浏览 3 评论 0原文

我已经使用此命令创建了一个密钥文件:


 sn.exe -k 2048 Build.snk

我想使用 .NET 读取此密钥。我找不到任何有关 .snk 格式的文档,所以我想知道 C# 中是否有办法读取 .snk 文件?

我提出这个问题的最初原因是将 .snk 文件用于签名程序集以外的目的。正如下面的答案之一所述,.snk 文件的目的实际上只是用于签署程序集。

I have created a key file with this command:


 sn.exe -k 2048 Build.snk

I would like to read in this key with .NET. I haven't been able to find any document as to the format of the .snk, so I'm wondering if there's a way in C# to read in an .snk file?

My original reason for asking the question was to use the .snk file for purposes other than signing an assembly. As one of the answers states below, the purpose of .snk files is really just for signing assemblies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自我难过 2024-09-13 11:28:50

此处在 MSDN 中找到了提及。这是代码:


public static void Main()
{
    // Open a file that contains a public key value. The line below  
    // assumes that the Strong Name tool (SN.exe) was executed from 
    // a command prompt as follows:
    //       SN.exe -k C:\Company.keys
    using (FileStream fs = File.Open("C:\\Company.keys", FileMode.Open))
    {
        // Construct a StrongNameKeyPair object. This object should obtain
        // the public key from the Company.keys file.
        StrongNameKeyPair k = new StrongNameKeyPair(fs);

        // Display the bytes that make up the public key.
        Console.WriteLine(BitConverter.ToString(k.PublicKey));

        // Close the file.
        fs.Close();
    }
}

Found a mention in MSDN here. Here's the code:


public static void Main()
{
    // Open a file that contains a public key value. The line below  
    // assumes that the Strong Name tool (SN.exe) was executed from 
    // a command prompt as follows:
    //       SN.exe -k C:\Company.keys
    using (FileStream fs = File.Open("C:\\Company.keys", FileMode.Open))
    {
        // Construct a StrongNameKeyPair object. This object should obtain
        // the public key from the Company.keys file.
        StrongNameKeyPair k = new StrongNameKeyPair(fs);

        // Display the bytes that make up the public key.
        Console.WriteLine(BitConverter.ToString(k.PublicKey));

        // Close the file.
        fs.Close();
    }
}

天荒地未老 2024-09-13 11:28:50

强命名密钥在编译时用于对编译器生成的程序集进行签名,因此在运行时读取它们可能不是您想要的。

首先,在 C# 项目的“属性”窗口中查找“签名”选项卡,您可以在其中选择用于对程序集进行签名的 .snk。

http://msdn.microsoft.com/en-us /library/xc31ft41(VS.100).aspx

Strong naming keys are used at compile-time to sign the assemblies produced by the compiler--so reading them in during runtime probably isn't what you want.

To get started look for the "Signing" tab in your C# Project's Properties window--there you can choose what .snk to sign the assembly with.

http://msdn.microsoft.com/en-us/library/xc31ft41(VS.100).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文