コード例 #1
0
        /// <summary>
        /// Decompresses the specified bytes
        /// </summary>
        /// <param name="compressedBytes"></param>
        /// <returns></returns>
        public static byte[] DecompressData(byte[] compressedBytes)
        {
            ByteArrayBuilder builder = new ByteArrayBuilder();

            try
            {
                MemoryStream ms = new MemoryStream(compressedBytes);

                ZipInputStream zipStream = new ZipInputStream(ms);

                const int CHUNK_SIZE = 10240;

                ZipEntry entry = zipStream.GetNextEntry();

                if (entry != null)
                {
                    int bytesRead = 0;

                    do
                    {
                        byte[] chunk = new byte[CHUNK_SIZE];
                        bytesRead = zipStream.Read(chunk, 0, CHUNK_SIZE);
                        builder.AddChunkReference(chunk, bytesRead);
                    }while (bytesRead > 0);
                }
            }
            catch (Exception ex)
            {
                SdkSettings.Instance.Logger.Log(TraceLevel.Warning, "Utils : DecompressData - Zip Exception: '{0}'", ex.Message);
            }
            return(builder.ToArray());
        }
コード例 #2
0
        /// <summary>
        /// Decrypts a from encrypted bytes
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static byte[] Decrypt(byte[] bytes)
        {
            ByteArrayBuilder result = new ByteArrayBuilder();

            try
            {
                RijndaelManaged rijndael = InitRijndael();

                ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);

                using (MemoryStream msDecrypt = new MemoryStream(bytes))
                {
                    using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                    {
                        using (BinaryReader srDecrypt = new BinaryReader(csDecrypt))
                        {
                            // Read the decrypted bytes from the decrypting stream
                            // and place them in a string.
                            int readBytes = 0;
                            do
                            {
                                byte[] buffer = new byte[READ_BUFFER_SIZE];
                                readBytes = srDecrypt.Read(buffer, 0, READ_BUFFER_SIZE);
                                if (readBytes > 0)
                                {
                                    result.AddChunkReference(buffer, readBytes);
                                }
                            }while (readBytes != 0);
                        }
                    }


                    rijndael.Clear();
                }
            }
            catch { };

            return(result.ToArray());
        }