如何从私钥创建签名? -DSA

发布于 2024-10-04 09:22:01 字数 765 浏览 6 评论 0原文

我正在尝试根据我提供的私钥和哈希值创建签名。我正在使用 DSA 和以下代码,但收到以下错误:

指定的类型无效。 source mscorlib

这条线上抛出错误: ImportCspBlob(pk)

 Private Function key() As String

        Dim privatekey As String = "-----BEGIN DSA PRIVATE KEY-----" _
        & "Key Data"
        & "-----END DSA PRIVATE KEY-----"

        Dim dsa As DSACryptoServiceProvider = New DSACryptoServiceProvider()
        Dim pk As Byte() = Encoding.ASCII.GetBytes(privatekey)

        dsa.ImportCspBlob(pk)
        Dim st As Byte() = Encoding.ASCII.GetBytes("THIS IS THE HASH STRING")))
        Dim signedValue As Byte() = dsa.SignHash(st, "SHA1")

        Return Encoding.ASCII.GetString(signedValue)

    End Function

谁能告诉我,我是否在正确的线路上,或者我出路了?

对此的任何帮助将不胜感激。

I am trying to create a signature from a private key that i have been provided and a hashed value. I am using DSA and the following code but receive the following error:

Invalid type specified.
source mscorlib

The error is thrown on this line: ImportCspBlob(pk)

 Private Function key() As String

        Dim privatekey As String = "-----BEGIN DSA PRIVATE KEY-----" _
        & "Key Data"
        & "-----END DSA PRIVATE KEY-----"

        Dim dsa As DSACryptoServiceProvider = New DSACryptoServiceProvider()
        Dim pk As Byte() = Encoding.ASCII.GetBytes(privatekey)

        dsa.ImportCspBlob(pk)
        Dim st As Byte() = Encoding.ASCII.GetBytes("THIS IS THE HASH STRING")))
        Dim signedValue As Byte() = dsa.SignHash(st, "SHA1")

        Return Encoding.ASCII.GetString(signedValue)

    End Function

Can anyone tell me if I am on the right lines herE or am I way out?

Any help on this would be much appreciated.

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

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

发布评论

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

评论(1

花期渐远 2024-10-11 09:22:01

您正在使用主要特定于 OpenSSL 的格式的 PEM 编码对象作为私钥。从根本上来说,它是一个基于 ASN.1 的结构,以 DER 进行编码,然后以 Base64 重新编码(以使其与 ASCII 兼容),最后配备一些标头(“BEGIN DSA PRIVATE KEY”)。另一方面,ImportCsbBlob() 需要一堆与 CryptoAPI 需要:DSA 关键元素的自定义、Microsoft 特定编码。

我在上面的段落中使用了大量的首字母缩写词,以强调从一种编码转换为另一种编码是一件复杂的事情这一事实。这些东西层次分明,彼此之间非常不同。

这篇 Blob 帖子 似乎告诉我们,OpenSSL 的一些最新版本可以进行以下转换:你。

You are using, as private key, a PEM-encoded object in a format which is mostly specific to OpenSSL. At its root, it is an ASN.1-based structure, encoded in DER, then re-encoded in Base64 (to make it ASCII-compatible), and finally equipped with some headers (the "BEGIN DSA PRIVATE KEY"). On the other hand, ImportCsbBlob() expects a bunch of bytes compatible with what CryptoAPI expects: a custom, Microsoft-specific encoding of the DSA key elements.

I have used an awful lot of acronyms in the paragraph above in order to underline the fact that converting from one encoding to another is a complex matter. Those things are heavily layered and very different from each other.

This blob post seems to tell that some very recent versions of OpenSSL can do the conversion for you.

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