Click here to Skip to main content
15,167,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

My project need to support chinese character.For this I have to encrypt chinese

string.I tried it in C++ and the resulted length is such a way that 8 character

length generates 64 length encrypted output,16 character length generates 128 length

encrypted output and so on.That is length of the encrypted string goes larger and

larger.I will explain how I did the encryption below

(1)Convert the chinese string to Base64 string using ToBase64String.

(2)Then encrypt the resulted string using a 32 length key

Here is my question.How to encrypt a chinese string using C# which should

generates small length output?

1 solution

Chinese string? What do you mean by that? There are not Chinese strings these days; there is only Unicode. Or do you mean one of the legacy encodings?

Now, why do you think you need to convert it to Base64String? What if I say that you need to convert it to array of byte, as it is always done? Use System.Text.Encoding to do that; see[^]. You could use any encoding except System.Text.ASCIIEncoding, of course; I would advise System.Text.UTF8Encoding.

Now, encryption. There is no such thing as "encrypt the resulted string using a 32 length key" — there is a number of algorithms. First, make a choice between symmetric or assymmetic algorithm. Please see[^],[^].

You will need good understanding of the ideas of encryption, which are not trivial.
Start here:[^] (these algorithms are assymmetric) and[^].

"Small length output"? Have you ever heard that there is no such thing as miracle? Ever heard of informatics? See[^].

I just thought: if you require a small length output, maybe you mean not encryption but cryptographic hash function ([^])? This is not encryption but is a completely different thing. Encrypted data can be decrypted, in contrast to hashed data which is irreversible, so it can be used only for comparison (and some related purposes). If so, I would advise using the algorithm from SHA family, see[^]. For .NET implementation, see[^].

Debojyoti Majumder 4-Aug-11 2:02am
Nice answer..
Thank you, Debojyoti.
kutz 2 4-Aug-11 2:50am
Thank you SAKryukov for your valuable information
You're very welcome.
If you agree it makes sense, please accept the answer formally (green button) -- thanks.
Kim Togo 4-Aug-11 3:53am
Good answer.
Thank you, Kim.
Soft009 4-Aug-11 4:18am
Good answer... :)
Thank you,
RaviRanjanKr 4-Aug-11 9:02am
Great answer SA, My 5+
Thank you very much, Ravi.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900