Beispiel #1
0
        public static string DecryptString(Stream stream, byte[] bytKey, byte[] bytVector)
        {
            SymmetricCryptography <TripleDESCryptoServiceProvider> sc = new SymmetricCryptography <TripleDESCryptoServiceProvider>(bytKey, bytVector);

            CryptoStream cStream = new CryptoStream(stream, sc._provider.CreateDecryptor(sc.Key, sc.IV), CryptoStreamMode.Read);

            byte[] bytLicense = null;
            int    bufferLen  = 4096;

            byte[] buffer = new byte[bufferLen];
            int    bytesRead;
            int    pos        = 0;
            int    totBytRead = 0;

            do
            {
                // read a chunk of data from the input file
                bytesRead   = cStream.Read(buffer, 0, bufferLen);
                totBytRead += bytesRead;

                if (bytesRead > 0)
                {
                    byte[] aux = bytLicense;

                    bytLicense = new byte[totBytRead];

                    if (aux != null)
                    {
                        aux.CopyTo(bytLicense, 0);
                    }

                    Array.Copy(buffer, 0, bytLicense, pos, bytesRead);

                    pos += bytesRead;
                }
            }while (bytesRead != 0);

            cStream.Close();
            cStream.Dispose();

            return(ASCIIEncoding.ASCII.GetString(bytLicense));
        }
Beispiel #2
0
        public static string DecryptString(string s, byte[] bytKey, byte[] bytVector)
        {
            SymmetricCryptography <TripleDESCryptoServiceProvider> sc = new SymmetricCryptography <TripleDESCryptoServiceProvider>(bytKey, bytVector);

            return(sc.Decrypt(s));
        }