Hi,

i encrypt a list of strings with RSACryptoServiceProvider.
I follow up this line
1. byte[] bytes = Text.Encoding.UTF8.getBytes(plaintext_string)
2. byte[] encr_bytes = rsa.encrypt(bytes)
3. string encr_string = Text.Encoding.UTF8.getString(encr_bytes)
The last string (encr_string) i store with ado.net in a sql 2005 server
database.

So far, so fine..

Now i have a input string from my application, with i encrypt with the same
RSACryptoServiceProvider with the same public key. And than i like to look in
the database, if this encrypted string is there, so i know than, that this
input was in the plaintext list without knowing the unencrypted list of
strings.

But when i make a simple SQL-Request mostly, i became no results...

Any ideas???

Thx
Nils

Re: store, compare and retrieve encrypted strings from sql 2005 server by Jon

Jon
Sat Apr 15 16:56:49 CDT 2006

Nils <Nils@discussions.microsoft.com> wrote:
> i encrypt a list of strings with RSACryptoServiceProvider.
> I follow up this line
> 1. byte[] bytes = Text.Encoding.UTF8.getBytes(plaintext_string)
> 2. byte[] encr_bytes = rsa.encrypt(bytes)
> 3. string encr_string = Text.Encoding.UTF8.getString(encr_bytes)

That last line is a really, really bad idea. After encryption, you've
just got a sequence of bytes. There is absolutely no guarantee that
they'll form a valid sequence of UTF-8-encoded characters.

If you want to convert arbitrary binary data into text in a reliable
way, use Base64 - that's what it's there for.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too