Exemplo n.º 1
0
        public static byte[] DecryptData(string password, AutoSaltSizes saltSize, byte[] data, SymmetricCryptoAlgorithm algorithm = SymmetricCryptoAlgorithm.AES_256_CBC)
        {
            DecryptionBuffer decBuffer = new DecryptionBuffer(password, saltSize, algorithm);

            decBuffer.AddData(data, true);
            return(decBuffer.GetData());
        }
Exemplo n.º 2
0
        public static void DecryptStream(string password, AutoSaltSizes saltSize, Stream inputStream, Stream outputStream, SymmetricCryptoAlgorithm algorithm = SymmetricCryptoAlgorithm.AES_256_CBC)
        {
            if (!inputStream.CanRead)
            {
                throw new Exception("The input stream has to support read");
            }
            if (!outputStream.CanWrite)
            {
                throw new Exception("The output stream has to support write");
            }

            DecryptionBuffer decBuffer = new DecryptionBuffer(password, saltSize, algorithm);

            byte[] readBuffer = new byte[500000];
            bool   isLastData = false;

            while (!isLastData)
            {
                int nrOfBytes = inputStream.Read(readBuffer, 0, readBuffer.Length);
                isLastData = (nrOfBytes == 0);

                decBuffer.AddData(readBuffer, 0, nrOfBytes, isLastData);
                byte[] decryptedData = decBuffer.GetData();
                outputStream.Write(decryptedData, 0, decryptedData.Length);
            }
        }
Exemplo n.º 3
0
        public string Decrypt(string cypherText)
        {
            String           pass      = Password;
            DecryptionBuffer decBuffer = new DecryptionBuffer(pass, Salt, SymmetricCryptoAlgorithm.AES_192_CBC);

            if (cypherText.Contains(" "))
            {
                return(cypherText);
            }
            decBuffer.AddData(Convert.FromBase64String(cypherText), true);
            byte[] decryptedBytes = decBuffer.GetData();
            return(Encoding.Unicode.GetString(decryptedBytes));
        }