Encryption and Decryption
-
Hai Everybody, I want to encrypt the user name and password given by the user separately and i have to store the encrypted content in sql server. yesterday our forum members suggested me to use the SHA256 algorithm so that i referred one article in our forum but it encrypts and decrypts some file contents. I felt very difficult to understand also. So can anyone suggest me some other simple and strong algorithm.
Best Regards, M. J. Jaya Chitra
-
Hai Everybody, I want to encrypt the user name and password given by the user separately and i have to store the encrypted content in sql server. yesterday our forum members suggested me to use the SHA256 algorithm so that i referred one article in our forum but it encrypts and decrypts some file contents. I felt very difficult to understand also. So can anyone suggest me some other simple and strong algorithm.
Best Regards, M. J. Jaya Chitra
The System.Security.Cryptographic namespace within the Microsoft .NET Framework provides a variety of tools to aid in encryption and decryption. The CryptoStream class is used here to demonstrate the encryption and decryption with System.Security.Cryptographic.SymmetricAlgorithm. For Details[^]
Regards, Satips.:rose:
-
Hai Everybody, I want to encrypt the user name and password given by the user separately and i have to store the encrypted content in sql server. yesterday our forum members suggested me to use the SHA256 algorithm so that i referred one article in our forum but it encrypts and decrypts some file contents. I felt very difficult to understand also. So can anyone suggest me some other simple and strong algorithm.
Best Regards, M. J. Jaya Chitra
I cant help you with SHA256, but maybe another solution is acceptable for you. I'am using the MD5, but this is only a unidirectional encryption. I show a dialog to enter a password and encrypt the password via MD5. The encrypted result will then be stored in a database. When the user logs on again, he must enter the password, which will be encrypted again with MD5. To verify if the password is correct i compare the encryption stored in the database, with the new encryption. To get the MD5 encryption do the following:
public static string StringToMd5(string text) { byte[] data = System.Text.Encoding.Unicode.GetBytes(text); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(data); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in result) { s.Append(b.ToString("x2").ToLower()); } return s.ToString(); }
may be it suits you... greets Snow
-
I cant help you with SHA256, but maybe another solution is acceptable for you. I'am using the MD5, but this is only a unidirectional encryption. I show a dialog to enter a password and encrypt the password via MD5. The encrypted result will then be stored in a database. When the user logs on again, he must enter the password, which will be encrypted again with MD5. To verify if the password is correct i compare the encryption stored in the database, with the new encryption. To get the MD5 encryption do the following:
public static string StringToMd5(string text) { byte[] data = System.Text.Encoding.Unicode.GetBytes(text); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(data); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in result) { s.Append(b.ToString("x2").ToLower()); } return s.ToString(); }
may be it suits you... greets Snow
-
Hai Everybody, I want to encrypt the user name and password given by the user separately and i have to store the encrypted content in sql server. yesterday our forum members suggested me to use the SHA256 algorithm so that i referred one article in our forum but it encrypts and decrypts some file contents. I felt very difficult to understand also. So can anyone suggest me some other simple and strong algorithm.
Best Regards, M. J. Jaya Chitra
using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; namespace Helper.Crypto { public class HashMethods { public static string GenerateSalt() { //Create 32 bytes of random data for use as a salt byte[] Salt = new byte[32]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetNonZeroBytes(Salt); return Encoding.UTF8.GetString(Salt); } public static string Hash(string text,string saltString) { string SaltedString = text + saltString; byte[] SaltedText = Encoding.UTF8.GetBytes(SaltedString); HashAlgorithm hash = new SHA512Managed(); byte[] hashBytes = hash.ComputeHash(SaltedText); return Convert.ToBase64String(hashBytes); } } }
I store both the salt and the hashed PWD+Salt in a DB. When a client tries to log in the server gives it the salt and the client adds the salt to the username and hashes. pass the hashed password up to the server and compare with the value stored in the DB. This way you never know the user's password. HTH Russ