Exemple #1
0
        /// <summary>
        /// Initializes encryption keys based on given <paramref name="password"/>.
        /// </summary>
        /// <param name="password">The password.</param>
        protected void InitializePassword(string password)
        {
            var pkManaged = new PkzipClassicManaged();

            byte[] key = PkzipClassic.GenerateKeys(ZipStrings.ConvertToArray(password));
            cryptoTransform_ = pkManaged.CreateEncryptor(key, null);
        }
Exemple #2
0
        private void CheckNameConversion(string toCheck)
        {
            byte[] intermediate = ZipStrings.ConvertToArray(toCheck);
            string final        = ZipStrings.ConvertToString(intermediate);

            Assert.AreEqual(toCheck, final, "Expected identical result");
        }
Exemple #3
0
        public void UnicodeNameConversion()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            ZipConstants.DefaultCodePage = 850;
            string sample = "Hello world";

            byte[] rawData = Encoding.ASCII.GetBytes(sample);

            string converted = ZipStrings.ConvertToStringExt(0, rawData);

            Assert.AreEqual(sample, converted);

            converted = ZipStrings.ConvertToStringExt((int)GeneralBitFlags.UnicodeText, rawData);
            Assert.AreEqual(sample, converted);

            // This time use some greek characters
            sample  = "\u03A5\u03d5\u03a3";
            rawData = Encoding.UTF8.GetBytes(sample);

            converted = ZipStrings.ConvertToStringExt((int)GeneralBitFlags.UnicodeText, rawData);
            Assert.AreEqual(sample, converted);
        }