C#从私钥中提取公钥 [英] Extract public key from private key in C#

查看:117
本文介绍了C#从私钥中提取公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 sn.exe 生成密钥对(私钥和公钥).我从私钥中提取公钥如下:

I used sn.exe to generate a key pair (private and public key). I extract a public key from private key as follows:

sn -p keyPair.snk publicKey.snk

我使用 C# 读取它并将其作为二进制存储在数据库中以用于加密我的数据.

I read it by using C# and store it in database as binary to use for encrypting my data.

有没有什么方法可以在不使用 sn.exe 的情况下从 C# 中的私钥中提取公钥?

Is there any way to extract a public key from a private key in C# without using sn.exe?

注意:我想要一个公钥作为字节,以便与我存储在数据库中的公钥进行比较.

NOTE : I want a public key as a byte to compare it with the one I store in my database.

推荐答案

在 C# 中有没有什么方法可以在不使用 sn.exe 的情况下从私钥中提取公钥?

Is there any way to extract a public key from a private key in C# without using sn.exe?

要做到这一点非常困难,但这是可能的;我已经这样做了.

It is surprisingly difficult to do that but it is possible; I have done so.

您需要做的是 p/invoke 到 mscorwks.dll 中的 StrongNameGetPublicKey.

What you need to do is p/invoke to StrongNameGetPublicKey in mscorwks.dll.

我使用 C# 读取它并将其作为二进制存储在数据库中以用于加密我的数据

I read it by using C# and store it in database as binary to use for encrypting my data

这是一个非常糟糕的主意.强名称公钥的目的不是加密您的数据!强名称公钥的目的是让您的客户验证您提供给他们的程序集是否由您编写.如果您将公钥用于除该任务之外的任何任务做一些非常非常错误的事情,你应该立即停止这样做.

This is an extremely bad idea. The purpose of a strong name public key is not to encrypt your data! The purpose of a strong name public key is for your customers to verify that the assembly you gave them was written by you. If you are using the public key for anything other than that task you are doing something very, very wrong and you should stop doing so immediately.

强名称使用加密,但不是加密技术;它们是一种证据生成技术,用于代码访问安全策略评估.

Strong names use encryption, but they are not an encryption technology; they are an evidence producing technology for the purpose of code access security policy evaluation.

这篇关于C#从私钥中提取公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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