Exemple #1
0
        public string DecodeAndSaveFile(string retornoFilePath)
        {
            var key      = this.GetCryptKey();
            var fileName = Path.GetFileName(retornoFilePath);

            try
            {
                var wis = new br.com.bradesco.webta.security.crypto.WEBTAInputStream(
                    fileName,
                    Path.GetDirectoryName(retornoFilePath),
                    key);

                int    readBytes = 0;
                byte[] aux       = new byte[512];
                var    baos      = new java.io.ByteArrayOutputStream();
                while ((readBytes = wis.read(aux, 0, aux.Length)) > 0)
                {
                    baos.write(aux, 0, readBytes);
                }

                var outputFile = string.Concat(Path.Combine(Path.GetDirectoryName(retornoFilePath), Path.GetFileNameWithoutExtension(fileName)), ".out.RET");
                File.WriteAllText(outputFile, baos.toString());

                wis.close();

                return(outputFile);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Falha ao descriptografar o arquivo '{0}'.", fileName), ex);
            }
        }