Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Encryption and Decryption

Encryption and Decryption

Scheduled Pinned Locked Moved C#
databasesql-serversysadminalgorithmssecurity
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M J Jaya Chitra
    wrote on last edited by
    #1

    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

    S P R 3 Replies Last reply
    0
    • M 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

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      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:

      1 Reply Last reply
      0
      • M 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

        P Offline
        P Offline
        Pixinger77
        wrote on last edited by
        #3

        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

        O 1 Reply Last reply
        0
        • P Pixinger77

          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

          O Offline
          O Offline
          originSH
          wrote on last edited by
          #4

          Just as a note MD5 is considered insecure now and it's recommended to change to the SHA-1 hash instead.

          1 Reply Last reply
          0
          • M 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

            R Offline
            R Offline
            Russell Jones
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups