Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i managed to make a simple program that encrypt and decrypt a text in c# using the aes algorithm but i have a few questions:
1) what is the best class and way to use the aes? cause i got those classes:AesManaged , RijndaelManaged , AesCryptoServiceProvider.
2) i understand there is a key size but i cant enter any other string rather than one that have 8 chars. so what to do?
3) why to use a string as a key isnt safe?
my code: [C#] aes - Pastebin.com[^]
ty for help!!!

What I have tried:

search tons in google about keys and all of that
Posted
Updated 1-Jun-16 7:46am

1 solution

It's all wrong. The "fact" that a key is somehow related to some strings is nothing but your fantasy. If you generated a key from a string, it's your problem. All cryptographic keys are just arrays of bytes. (Please see Aes Class (System.Security.Cryptography)[^].) Also, you should understand that those keys have nothing to do with the concept of "password".

And, just in case: if you think that a password (I'm talking about real passwords now) can be encrypted and stored, think again: the idea would be totally unsafe. Passwords should never be stored anywhere or transmitted via the network for authentication. If you feel confused or disagree, read about cryptographic has functions and their use for password-based authentication.
I have no idea what is your purpose, and this is bad. This is the fist thing you had to explain. The whole idea of symmetric encryption is questionable for most applications. You need to understand some basic cryptographic ideas first. Please see:
Symmetric-key algorithm — Wikipedia, the free encyclopedia[^],
Public-key cryptography — Wikipedia, the free encyclopedia[^],
Cryptography — Wikipedia, the free encyclopedia[^].

—SA
 
Share this answer
 
Comments
Member 12181103 1-Jun-16 14:34pm    
i understand i explained my self bad.
i know understand that its not what i taught and i will re ask the questions:
1) why i cant convert a any other string rather than a 8 char long string to array of a byte and use it as my key?
2) why to do like that ^ is less safe than that: https://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes%28v=vs.110%29.aspx
3) what is the best class and way to use the aes? cause i got those classes:AesManaged , RijndaelManaged , AesCryptoServiceProvider.
ty for answer and for your time!!!!
Sergey Alexandrovich Kryukov 1-Jun-16 14:57pm    
1) You can represent absolutely any string as an array of bytes, but the result depends on the chosen encoding.
I have no idea where did you get "8 char long". It's not "conversion". It can be  System.Text.Encoding.GetBytes.

2) What is less safe than what? I don't understand. You link is related to key generation.

3) No, they are: System.Security.Cryptography.AesCng, System.Security.Cryptography.AesCryptoServiceProvider, System.Security.Cryptography.AesManaged. You can find some considerations here: http://stackoverflow.com/questions/1228451/when-would-i-choose-aescryptoserviceprovider-over-aesmanaged-or-rijndaelmanaged, http://stackoverflow.com/questions/13486109/rijndaelmanaged-vs-aescryptoserviceprovider-aes-encryption.

AES can be considered as a special case of Rijndael symmetric algorithm.

—SA
Member 12181103 1-Jun-16 15:11pm    
http://stackoverflow.com/questions/34343500/why-does-any-length-key-work-for-rijndaelmanaged/34354643#34354643
in the second comment to the question he said its less safer. why?

and in the code that i have: http://pastebin.com/NWj3pi2Y
this is the only length of string that i can do: ggwpgiy2
why?
thank you for you answers!!!!!!
Sergey Alexandrovich Kryukov 1-Jun-16 16:05pm    
On that page, I could not even find the word "safer".

I don't understand what "the only length of string that I can do" means. "ggwpgiy2" is not a length, this is a string. I have no idea why do you do it all.

—SA
Member 12181103 1-Jun-16 16:34pm    
Ok so what i want to do is to make a program the will encrypt and decrypt text with aes algorithem.
The key a "password" they will choose too help them decrypt it later.
So i searched online and i found what i found but i can do bigger string like: passwords.
Its too long.
There is a certain length i can enter right?

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