|
Post by mikehild on Aug 31, 2009 18:21:38 GMT -5
I'm new to encryption and am figuring out how to do it in VB as I may have a need to decrypt credit card data from our new web store.
I've figured out how to create a test string, encrypt it, and decrypt it right away in the same function, but my next step is to try and load the private key we have, and decrypt existing data. We won't need to encrypt anything, just decrypt what I've already downloaded from our web store.
The key I have is in a text file (named asc_rsa_private_key_2008_10_15.txt), in the format of "n:(256 characters);d:(another 256 characters);" and it appears that the 256 characters are hexadecimal, rather than base-64.
If anyone could help me out here or point me in the right direction, it would be much appreciated. I've tried several different things and none of them work, but I'm sure my main problem is that I'm just not interpreting the file with the key correctly. Perhaps I need to convert the values to another format first, then I can load them into the RSAParameters object? Or it could be that I'm mistaken and it's not RSA at all (I assumed so, due to the "rsa" in the key filename).
Thanks, Mike
|
|
|
Post by mikehild on Sept 1, 2009 17:56:26 GMT -5
Okay, I've made a bit of progress. I've determined that the key file I has does indeed contain an RSA key stored as hex values, so I put together some code to read in the file, convert the hex values to 1024-bit integers, then convert those to base-64. But now, I can't get RSACryptoServiceProvider's FromXMLString method to accept it as a private key.
What I've done, is to enclose the base-64 encoded values in XML, i.e. <RSAKeyValue><Modulus>("n" from file)</Modulus><D>("d" from file)</D></RSAKeyValue>, but then FromXMLString reports "Invalid XML Format." If I enclose the "d" in <Exponent> tags instead of <D> it accepts it, but then it thinks it's a public key and I can only encrypt, not decrypt. I also tried leaving the <D> tags intact and putting in a set of empty <Exponent> tags but that also gives an "Invalid XML Format" error. Now if I put dummy values in the <Exponent> tags, such as 1234, it accepts it, but the PublicOnly property still says True and any attempt at decryption still yields a "Key does not exist" error.
I really hope I don't need to figure out how to calculate values for P, Q, DP, DQ, and InverseQ to include those as well? My current understanding of RSA is that for a private key you only need n and d to decrypt the data.
|
|