I am trying to mimic the results of some C code that uses the OpenSSL library using the system.security.crytography library in the .net 3.5 world, and I can't seem to get it right. I need some help... part of the issue is my understanding of crytography in general.
Here's what is supposed to happen:
- I send a request for authentication to a device.
- It returns a challenge digest, which I then need to sign with a known key and return
- The device returns a "success" or "Fail" message.
I have the following code snippet that I am trying to "copy":
//Seed the PRNG
//Cheating here - the PRNG will be seeded when we create a key pair
//The key pair is discarded only doing this to seed the PRNG.
DSA *temp_dsa = DSA_new();
if(!temp_dsa)
{
printf("Error: The client had an error with the DSA API\n");
exit(0);
}
unsigned char seed[20] = "Our Super Secret Key";
temp_dsa = DSA_generate_parameters(128, seed, sizeof(seed), NULL, NULL, NULL, NULL);
DSA_free(temp_dsa);
//A pointer to the private key.
p = (unsigned char *)&priv_key;
//Create and allocate a DSA structure from the private key.
DSA *priv_dsa = NULL;
priv_dsa = d2i_DSAPrivateKey(NULL, &p, sizeof(priv_key));
if(!priv_dsa)
{
printf("Error: The client had an error with the DSA API\n");
exit(0);
}
//Allocate memory for the to be computed signature.
sigret = OPENSSL_malloc(DSA_size(priv_dsa));
//Sign the challenge digest recieved from the ISC.
retval = DSA_sign(0, pResp->data, pResp->data_length, sigret, &siglen, priv_dsa);
A few more bits of information:
priv_key is a 252 element character array of hex characters that is included.
The end result is a 512 (or less) array of characters to send back for validation to the device.
Rasmus asked to see the key array. Here it is:
unsigned char priv_key[] = {0x30, 0x81, 0xf9, 0x02, 0x01, 0x00,
0x02, 0x41, 0x00, 0xfe, 0xca,
0x97, 0x55, 0x1f, 0xc0, 0xb7,
0x1f, 0xad, 0xf0, 0x93, 0xec,
0x4b, 0x31, 0x94, 0x78, 0x86,
0x82, 0x1b, 0xab, 0xc4, 0x9e,
0x5c, 0x40, 0xd9, 0x89, 0x7d,
0xde, 0x43, 0x38, 0x06, 0x4f,
0x1b, 0x2b, 0xef, 0x5c, 0xb7,
0xff, 0x21, 0xb1, 0x11, 0xe6,
0x9a, 0x81, 0x9a, 0x2b, 0xef,
0x3a,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0x28, 0x02, 0x15,
0xce, 0x47, 0xaa, 0xce, 0x6e,
0xfe};
Can anyone help me translate this code to it's VB.net crypto equivalent?
TIA,
Glenn