Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Byte to char conversions
Message
De
18/03/2004 08:10:20
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Byte to char conversions
Divers
Thread ID:
00887452
Message ID:
00887452
Vues:
41
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
Fil
Voir

Click here to load this message in the networking platform