Click here to Skip to main content
15,900,254 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Securing Local Files [Solved] Pin
James H3-Sep-12 22:21
James H3-Sep-12 22:21 
GeneralRe: Securing Local Files [Solved] Pin
Saul Johnson5-Sep-12 4:07
Saul Johnson5-Sep-12 4:07 
AnswerRe: Securing Local Files [Solved] Pin
Stephane Rivette At Motion4-Sep-12 2:07
Stephane Rivette At Motion4-Sep-12 2:07 
GeneralRe: Securing Local Files [Solved] Pin
Eddy Vluggen4-Sep-12 5:15
professionalEddy Vluggen4-Sep-12 5:15 
AnswerRe: Securing Local Files [Solved] Pin
BrainiacV4-Sep-12 8:30
BrainiacV4-Sep-12 8:30 
GeneralRe: Securing Local Files [Solved] Pin
Saul Johnson5-Sep-12 4:05
Saul Johnson5-Sep-12 4:05 
AnswerRe: Securing Local Files [Solved] Pin
ObiWan_MCC5-Sep-12 3:51
ObiWan_MCC5-Sep-12 3:51 
GeneralRe: Securing Local Files [Solved] Pin
ObiWan_MCC5-Sep-12 4:02
ObiWan_MCC5-Sep-12 4:02 
forgot; as for encrypting/decrypting, you may use the following code (not mine, but I'm sorry to say I don't remember where I found it)

C#
// Encrypt the given string using AES.  The string can be decrypted using 
// DecryptString().  The sharedSecret parameters must match.
public string EncryptString(string plainText, string sharedSecret)
{
    if (string.IsNullOrEmpty(plainText))
        throw new ArgumentNullException("plainText");
    if (string.IsNullOrEmpty(sharedSecret))
        throw new ArgumentNullException("sharedSecret");

    string outStr = null;                       // Encrypted string to return
    RijndaelManaged aesAlg = null;              // RijndaelManaged object used to encrypt the data.

    try
    {
        // generate the key from the shared secret and the salt
        Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(sharedSecret, this._salt);

        // Create a RijndaelManaged object
        aesAlg = new RijndaelManaged();
        aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);

        // Create a decrytor to perform the stream transform.
        ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

        // Create the streams used for encryption.
        using (MemoryStream msEncrypt = new MemoryStream())
        {
            // prepend the IV
            msEncrypt.Write(BitConverter.GetBytes(aesAlg.IV.Length), 0, sizeof(int));
            msEncrypt.Write(aesAlg.IV, 0, aesAlg.IV.Length);
            using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
            {
                using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                {
                    //Write all data to the stream.
                    swEncrypt.Write(plainText);
                }
            }
            outStr = Convert.ToBase64String(msEncrypt.ToArray());
        }
    }
    finally
    {
        // Clear the RijndaelManaged object.
        if (aesAlg != null)
            aesAlg.Clear();
    }

    // Return the encrypted bytes from the memory stream.
    return outStr;
}

// Decrypt the given string.  Assumes the string was encrypted using 
// EncryptString(), using an identical sharedSecret.
public string DecryptString(string cipherText, string sharedSecret)
{
    if (string.IsNullOrEmpty(cipherText))
        throw new ArgumentNullException("cipherText");
    if (string.IsNullOrEmpty(sharedSecret))
        throw new ArgumentNullException("sharedSecret");

    // Declare the RijndaelManaged object
    // used to decrypt the data.
    RijndaelManaged aesAlg = null;

    // Declare the string used to hold
    // the decrypted text.
    string plaintext = null;

    try
    {
        // generate the key from the shared secret and the salt
        Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(sharedSecret, this._salt);

        // Create the streams used for decryption.                
        byte[] bytes = Convert.FromBase64String(cipherText);
        using (MemoryStream msDecrypt = new MemoryStream(bytes))
        {
            // Create a RijndaelManaged object
            // with the specified key and IV.
            aesAlg = new RijndaelManaged();
            aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);
            // Get the initialization vector from the encrypted stream
            aesAlg.IV = ReadByteArray(msDecrypt);
            // Create a decrytor to perform the stream transform.
            ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
            using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
            {
                using (StreamReader srDecrypt = new StreamReader(csDecrypt))

                    // Read the decrypted bytes from the decrypting stream
                    // and place them in a string.
                    plaintext = srDecrypt.ReadToEnd();
            }
        }
    }
    finally
    {
        // Clear the RijndaelManaged object.
        if (aesAlg != null)
            aesAlg.Clear();
    }

    return plaintext;
}


the above should be robust enough for your task, just encrypt the received password calling "EncryptString()" and passing (e.g.) the "session ID" as the key, store it into a session cookie and then use "DecryptString()" to retrieve it when needed (for the current session lifetime)
GeneralRe: Securing Local Files [Solved] Pin
Saul Johnson5-Sep-12 4:03
Saul Johnson5-Sep-12 4:03 
GeneralRe: Securing Local Files [Solved] Pin
ObiWan_MCC5-Sep-12 4:36
ObiWan_MCC5-Sep-12 4:36 
QuestionArrow keys to move an object Pin
Steven St. John1-Sep-12 11:30
Steven St. John1-Sep-12 11:30 
AnswerRe: Arrow keys to move an object Pin
ChandraRam2-Sep-12 23:57
ChandraRam2-Sep-12 23:57 
GeneralRe: Arrow keys to move an object Pin
Steven St. John3-Sep-12 3:35
Steven St. John3-Sep-12 3:35 
GeneralRe: Arrow keys to move an object Pin
ChandraRam3-Sep-12 4:00
ChandraRam3-Sep-12 4:00 
GeneralRe: Arrow keys to move an object Pin
Steven St. John3-Sep-12 7:25
Steven St. John3-Sep-12 7:25 
AnswerRe: Arrow keys to move an object Pin
Alan N3-Sep-12 6:00
Alan N3-Sep-12 6:00 
GeneralRe: Arrow keys to move an object Pin
Steven St. John3-Sep-12 7:32
Steven St. John3-Sep-12 7:32 
AnswerRe: Arrow keys to move an object Pin
Sonhospa3-Sep-12 7:14
Sonhospa3-Sep-12 7:14 
GeneralRe: Arrow keys to move an object Pin
Steven St. John3-Sep-12 7:35
Steven St. John3-Sep-12 7:35 
GeneralRe: Arrow keys to move an object Pin
Sonhospa3-Sep-12 21:30
Sonhospa3-Sep-12 21:30 
QuestionDataContext Not Updating Its Database Pin
Sonhospa31-Aug-12 23:16
Sonhospa31-Aug-12 23:16 
AnswerRe: DataContext Not Updating Its Database Pin
Sonhospa3-Sep-12 7:21
Sonhospa3-Sep-12 7:21 
QuestionToggling ON/OFF VB6 reference library in Visual Studio Pin
juno10131-Aug-12 6:27
juno10131-Aug-12 6:27 
AnswerRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
Dave Kreskowiak31-Aug-12 7:26
mveDave Kreskowiak31-Aug-12 7:26 
GeneralRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
juno10131-Aug-12 9:06
juno10131-Aug-12 9:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.