none
ASP.NET Getting Started FAQ: Bagaimana saya bisa mengenkripsi string seperti password atau QueryStrings? (Part 1) RRS feed

  • Diskusi Umum

  • DES encryption, MD5 dan berbagai cara lain bisa melakukannya:

    Berikut adalah contoh dari DES encryption:

    const string DESKey = "AQWSEDRF"; 
    const string DESIV = "HGFEDCBA"; 
     
    public static string DESDecrypt(string stringToDecrypt) 
    { 
        byte[] key; 
        byte[] IV; 
        byte[] inputByteArray; 
        key = Convert2ByteArray(DESKey); 
        IV = Convert2ByteArray(DESIV); 
        int len = stringToDecrypt.Length; 
        inputByteArray = Convert.FromBase64String(stringToDecrypt); 
        DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
        MemoryStream ms = new MemoryStream(); 
        CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write); 
        try 
        { 
            cs.Write(inputByteArray, 0, inputByteArray.Length); 
            cs.FlushFinalBlock(); 
            Encoding encoding = Encoding.UTF8; 
            return encoding.GetString(ms.ToArray()); 
        } 
        catch (System.Exception ex) 
        { 
            throw ex; 
        } 
        finally 
        { 
            ms.Close(); 
            cs.Close(); 
        } 
    } 

    Berlanjut ke ASP.NET Getting Started FAQ: Bagaimana saya bisa mengenkripsi string seperti password atau QueryStrings? (Part 2)


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Selasa, 05 Juli 2011 09.18
    Moderator