コード例 #1
0
        /// <summary>
        /// Initializes encryption keys based on given <paramref name="password"/>.
        /// </summary>
        /// <param name="password">The password.</param>
        protected void InitializePassword(string password)
        {
#if NETCF_1_0
            keys = new uint[] {
                0x12345678,
                0x23456789,
                0x34567890
            };

            byte[] rawPassword = ZipConstants.ConvertToArray(password);

            for (int i = 0; i < rawPassword.Length; ++i)
            {
                UpdateKeys((byte)rawPassword[i]);
            }
#else
            PkzipClassicManaged pkManaged = new PkzipClassicManaged();
            byte[] key = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(password));
            cryptoTransform_ = pkManaged.CreateEncryptor(key, null);
#endif
        }
コード例 #2
0
        private Stream CreateAndInitEncryptionStream(Stream baseStream, ZipEntry entry)
        {
            CryptoStream stream = null;

            if ((entry.Version < 50) || ((entry.Flags & 0x40) == 0))
            {
                PkzipClassicManaged managed = new PkzipClassicManaged();
                this.OnKeysRequired(entry.Name);
                if (!this.HaveKeys)
                {
                    throw new ZipException("No password available for encrypted stream");
                }
                stream = new CryptoStream(baseStream, managed.CreateEncryptor(this.key, this.iv), CryptoStreamMode.Write);
                if ((entry.Crc < 0L) || ((entry.Flags & 8) != 0))
                {
                    this.WriteEncryptionHeader(stream, entry.DosTime << 0x10);
                    return(stream);
                }
                this.WriteEncryptionHeader(stream, entry.Crc);
            }
            return(stream);
        }
コード例 #3
0
		/// <summary>
		/// Initializes encryption keys based on given <paramref name="password"/>.
		/// </summary>
		/// <param name="password">The password.</param>
		protected void InitializePassword(string password)
		{
#if NETCF_1_0
			keys = new uint[] {
				0x12345678,
				0x23456789,
				0x34567890
			};
			
			byte[] rawPassword = ZipConstants.ConvertToArray(password);
			
			for (int i = 0; i < rawPassword.Length; ++i) {
				UpdateKeys((byte)rawPassword[i]);
			}
			
#else			
			PkzipClassicManaged pkManaged = new PkzipClassicManaged();
			byte[] key = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(password));
			cryptoTransform_ = pkManaged.CreateEncryptor(key, null);
#endif
		}
コード例 #4
0
ファイル: ZipFile.cs プロジェクト: nolanlum/4chanscraper
        Stream CreateAndInitEncryptionStream(Stream baseStream, ZipEntry entry)
        {
            CryptoStream result = null;
            if ( (entry.Version < ZipConstants.VersionStrongEncryption)
                || (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0) {
                PkzipClassicManaged classicManaged = new PkzipClassicManaged();

                OnKeysRequired(entry.Name);
                if (HaveKeys == false) {
                    throw new ZipException("No password available for encrypted stream");
                }

                // Closing a CryptoStream will close the base stream as well so wrap it in an UncompressedStream
                // which doesnt do this.
                result = new CryptoStream(new UncompressedStream(baseStream),
                    classicManaged.CreateEncryptor(key, null), CryptoStreamMode.Write);

                if ( (entry.Crc < 0) || (entry.Flags & 8) != 0) {
                    WriteEncryptionHeader(result, entry.DosTime << 16);
                }
                else {
                    WriteEncryptionHeader(result, entry.Crc);
                }
            }
            return result;
        }