Encoding Issue After Decrypt

I’m using RSA crypto to encrypt a string and then I encode it to hex before writing it to a textarea. Then when I copy the hex from my textarea into my app into a string constant and decode the hex and then decrypt the string, I get a string back that is slightly different than the original string and I need it to be exactly the same.

I noticed that there is an extra space in the decrypted string after the - character and there are some extra spaces after the : character in my output when I write it to a text file for comparison with the original.

Also if I rename the temp text file .txt and try to view it in notepad I get nothing but chars. Some of it looks like this:

???????????????????????????

But if I decode and decrypt to a textarea and not to a temp file everything is spaced properly and looks normal.

Can anyone give me some advice on how to fix this? Thanks!

EDIT*

I opened the temp text file up in notepad++ to work with the encodings easier and I am getting a NUL after each - char in my decrypted text file. Anyone know how to prevent this?

When you decrypt your hex you need to define the encoding

Thanks Norman I added:

decryptedData = ReplaceAllB(decryptedData,&u0,"") decryptedData = ConvertEncoding(decryptedData, Encodings.UTF8)

That solved my null issues, code still isn’t working though, it must me something else.

Thanks.

You first need to define the encoding, and then – if necessary - convert it.

decryptedData = decryptedData.DefineEncoding(Encodings.WhatEverEncodingItIs).ConvertEncoding(Encodings.UTF8)

Thanks Eli, I finally got it working though. I’ll definitely try your suggestion too.

[quote=183615:@Ryan Haynes]Thanks Norman I added:

decryptedData = ReplaceAllB(decryptedData,&u0,"") decryptedData = ConvertEncoding(decryptedData, Encodings.UTF8)

That solved my null issues, code still isn’t working though, it must me something else.

Thanks.[/quote]
Dont replace all the nulls
They may actually be important for certain encodings

You should only need to decode the hex then define the encoding as UTF8 since this is data that originated in your code (from a constant)