Re: Converting CryptAcquireContext -> System.Security.Cryptography.SymmetricAlgorithm

From: HaukiDog (HaukiDog_at_hotmail.com)
Date: 04/29/03


Date: 28 Apr 2003 15:57:27 -0700


Hi again, here is what I have, it's not working. Am I using the hash
correctrly?

public string EncryptTest(string Value, string Key)
{
        ASCIIEncoding TextConverter = new ASCIIEncoding();
        ARCFourManaged myARCFour = new ARCFourManaged();

        byte[] myByteKey = TextConverter.GetBytes(Key);
        MD5 md5 = new MD5CryptoServiceProvider();
        myARCFour.Key = md5.ComputeHash(myByteKey);

        ICryptoTransform encryptor = myARCFour.CreateEncryptor();
        MemoryStream msEncrypt = new MemoryStream();
        CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor,
CryptoStreamMode.Write);

        //Convert the data to a byte array.
        Byte [] toEncrypt = TextConverter.GetBytes(Value);

        //Write all data to the crypto stream and flush it.
        csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
        csEncrypt.FlushFinalBlock();

        byte [] encrypted = msEncrypt.ToArray();
        string EncryptedString = TextConverter.GetString(encrypted);

        return EncryptedString;
}