John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Titre:
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.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement