Question

I'm using .NET's RijndaelManaged class to encrypt and decrypt strings. 3 different strings are first encrypted and then concatenated, separated by a pipe (|), and then this string is saved back to the database.

When I need to decrypt the string, I first separate the three encrypted strings and then decrypt them.

I'm concatenating the individual encrypted strings as follows:

StringBuilder sb = new StringBuilder();
sb.Append(Crypto.Encrypt("string1")).Append("|")
.Append(Crypto.Encrypt("string2")).Append("|")
          Crypto.Encrypt("string3"));

My question is: When encrypting a string using RijndaelManaged, can the encrypted string include the pipe sign?

Was it helpful?

Solution

I'm using .NET's RijndaelManaged class to encrypt and decrypt strings.

You may be using that as the underlying encryption - but RijndaelManaged only deals with binary data, as is normally the case with encryption code.

So presumably you're converting your string into bytes (hopefully using a sensible encoding such as UTF-8), then encrypting, then converting the encrypted bytes back into a string.

Without knowing how you're converting the encrypted bytes back into a string, we can't possibly know whether the results will include a |. If you're using Convert.ToBase64String (which is probably what I'd use) you'll be fine, as | isn't used within the normal base64 alphabet. Ditto if you're just converting each byte into two hex digits. But maybe you're doing something else. (If you're using Encoding, you're doing it wrong by the way, and can easily lose data.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top