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

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?
Posted

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 http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^]. 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 http://msdn.microsoft.com/en-us/library/system.security.cryptography.symmetricalgorithm.aspx[^], http://msdn.microsoft.com/en-us/library/system.security.cryptography.asymmetricalgorithm.aspx[^].

You will need good understanding of the ideas of encryption, which are not trivial.
Start here: http://en.wikipedia.org/wiki/Public-key_cryptography[^] (these algorithms are assymmetric) and http://en.wikipedia.org/wiki/Symmetric_key_algorithms[^].

"Small length output"? Have you ever heard that there is no such thing as miracle? Ever heard of informatics? See http://en.wikipedia.org/wiki/Informatics_%28academic_field%29[^].

[EDIT]
I just thought: if you require a small length output, maybe you mean not encryption but cryptographic hash function (http://en.wikipedia.org/wiki/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 http://en.wikipedia.org/wiki/SHA-2[^]. For .NET implementation, see http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Debojyoti Majumder 4-Aug-11 2:02am    
Nice answer..
Sergey Alexandrovich Kryukov 4-Aug-11 2:04am    
Thank you, Debojyoti.
--SA
kutz 2 4-Aug-11 2:50am    
Thank you SAKryukov for your valuable information
Sergey Alexandrovich Kryukov 4-Aug-11 3:57am    
You're very welcome.
If you agree it makes sense, please accept the answer formally (green button) -- thanks.
--SA
Kim Togo 4-Aug-11 3:53am    
Good answer.

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