Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
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.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.