John Baird
Coatesville, Pennsylvania, United States
General information
Title:
Byte to char conversions
I hope I can articulate this so that you can understand the problem. I built to classes: Encrypt and Decrypt according to MSDN article. When I run the program to encrypt and decrypt strings with the test program, everything works fine. The process is:
plaintext = "this is to be encrypted"
ciphertext = encrypt(plaintext)
returntext = decrypt(ciphertext)
in this example plaintext and returntext are identical.
I am trying to store the results of the encrypt to a registry string. ciphertext is a byte[] on the return so I am converting it to string for storage in the registry by using:
mystring = Convert.ToBase64String(cipherText)
in this example, ciphertext has a length of 48. I store mystring to the registry and retrieve it. This works fine. When I convert the plaintext from the registry back into a byte[] using:
cipherText = Encoding.ASCII.GetBytes(mystring);
the length is now 64 for ciphertext and the decrypt function fails returning an error message about PCKS7 padding is invalid.
How can I store the ciphertext to the registry and reconvert it back to byte[] without physically changing the data? Hope this makes sense. Thanks.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only