Password encryption

后端 未结 5 815
耶瑟儿~
耶瑟儿~ 2021-01-14 15:38

I am creating a login screen for an application in C#. In my login screen I am reading the username and password from the database and checking whether the entered username

5条回答
  •  借酒劲吻你
    2021-01-14 16:05

    You can encrypt the passwords in many ways.

    One of the way is using the MD5 encryption. Let me show you one of the encryption method that I am using.

    #region Encrypt
    public string Encrypt(string simpletext, string keys)
    {
        try
        {
            XCryptEngine xe = new XCryptEngine();
    
            xe.Algorithm = XCrypt.XCryptEngine.AlgorithmType.DES; //DES = Data Encryption Standard
    
            string cipher = xe.Encrypt(simpletext, keys);
            if (cipher != null)
                return (cipher);
            else
                return null;
        }
    
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #endregion
    
    #region Decrypt
    public string Decrypt(string simpletext, string keys)
    {
        try
        {
            XCryptEngine xe = new XCryptEngine();
    
            xe.Algorithm = XCrypt.XCryptEngine.AlgorithmType.DES;
    
            //Console.WriteLine(xe.Decrypt(simpletext, keys));
            simpletext = simpletext.Replace(" ", "+");
            string cipertext = xe.Decrypt(simpletext, keys);
            if (cipertext != null)
                return (cipertext);
            else
                return null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #endregion
    

    you need to use reference for XCrypt to use this.

    using XCrypt;
    

提交回复
热议问题