Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                        byte[] saltByte = new byte[8];
                       
                        rng.GetBytes(saltByte);

                        string salt = Convert.ToBase64String(saltByte);

                        SHA512Managed hashing = new SHA512Managed();

                        string hash = textboxpassword.text + salt;

                        byte[] bytes = Encoding.Unicode.GetBytes(hash);

                        byte[] hash = hashing.ComputeHash(bytes);

                        hashes = Convert.ToBase64String(hash1);


Here is my sample data, is my salt in the hash?
Password - P3w1VyHK0PgLmWdCuG4pzCOuTK2/xMrK2UC2S7ZBJy45NC34r9uf3qRODtw9m287tMQfo4QAB5TuFwvc9E/4cg==

Salt -
drYJ2AJJNBc=
Posted
Updated 16-Jul-14 23:10pm
v3

Of course it is: you have explicitely put it into the input data.
 
Share this answer
 
Comments
polkj 17-Jul-14 5:30am    
Really, but the salt value is not inside
No. It does however make your encrypted data pretty strongly encrypted - since you use a random salt value and don't appear to save it - which is going to make it pretty much impossible for you to decode it unless you store the whole has somewhere - which kinda defeats the point, really.

The idea of using a salt is not to increase the strength of the encryption, but to make the same text encrypted for different users different: so if 50 of your users have the same password you can't tell what it is by using the same one - the salt means that the encrypted value is different.

There are two suggestions I would make here: combine the password with some unique information (such as the user number or even userID) and use that as the value to encrypt. The uniqueness of the user data ensures that identical values don't generate the same output.
Second, don't encrypt passwords. Ever. Hash them instead: Password Storage: How to do it.[^]
 
Share this 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