当前位置: 首页>>代码示例>>C#>>正文


C# PkzipClassicManaged.CreateDecryptor方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Encryption.PkzipClassicManaged.CreateDecryptor方法的典型用法代码示例。如果您正苦于以下问题:C# PkzipClassicManaged.CreateDecryptor方法的具体用法?C# PkzipClassicManaged.CreateDecryptor怎么用?C# PkzipClassicManaged.CreateDecryptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Encryption.PkzipClassicManaged的用法示例。


在下文中一共展示了PkzipClassicManaged.CreateDecryptor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAndInitDecryptionStream

		Stream CreateAndInitDecryptionStream(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");
				}

				result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
				CheckClassicPassword(result, entry);
			}
			else {
#if !NET_1_1 && !NETCF_2_0
				if (entry.Version == ZipConstants.VERSION_AES) {
					//
					OnKeysRequired(entry.Name);
					if (HaveKeys == false) {
						throw new ZipException("No password available for AES encrypted stream");
					}
					int saltLen = entry.AESSaltLen;
					byte[] saltBytes = new byte[saltLen];
					int saltIn = baseStream.Read(saltBytes, 0, saltLen);
					if (saltIn != saltLen)
						throw new ZipException("AES Salt expected " + saltLen + " got " + saltIn);
					//
					byte[] pwdVerifyRead = new byte[2];
					baseStream.Read(pwdVerifyRead, 0, 2);
					int blockSize = entry.AESKeySize / 8;	// bits to bytes

					ZipAESTransform decryptor = new ZipAESTransform(rawPassword_, saltBytes, blockSize, false);
					byte[] pwdVerifyCalc = decryptor.PwdVerifier;
					if (pwdVerifyCalc[0] != pwdVerifyRead[0] || pwdVerifyCalc[1] != pwdVerifyRead[1])
						throw new ZipException("Invalid password for AES");
					result = new ZipAESStream(baseStream, decryptor, CryptoStreamMode.Read);
				}
				else
#endif
				{
					throw new ZipException("Decryption method not supported");
				}
			}

			return result;
		}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:49,代码来源:ZipFile.cs

示例2: InitialRead

		// Perform the initial read on an entry which may include 
		// reading encryption headers and setting up inflation.
		int InitialRead(byte[] destination, int offset, int count)
		{
			if (entry.Version > ZipConstants.VERSION_MADE_BY) {
				throw new ZipException("Libray cannot extract this entry version required (" + entry.Version.ToString() + ")");
			}
			
			// test for encryption
			if (entry.IsCrypted) {
		
				if (password == null) {
					throw new ZipException("No password set.");
				}
			
				// Generate and set crypto transform...
				PkzipClassicManaged managed = new PkzipClassicManaged();
				byte[] key = PkzipClassic.GenerateKeys(Encoding.ASCII.GetBytes(password));
					
				inputBuffer.CryptoTransform = managed.CreateDecryptor(key, null);
			
				byte[] cryptbuffer = new byte[ZipConstants.CRYPTO_HEADER_SIZE];
				inputBuffer.ReadClearTextBuffer(cryptbuffer, 0, ZipConstants.CRYPTO_HEADER_SIZE);
					
				if ((flags & 8) == 0) {
					if (cryptbuffer[ZipConstants.CRYPTO_HEADER_SIZE - 1] != (byte)(entry.Crc >> 24)) {
						throw new ZipException("Invalid password");
					}
				}
				else {
					if (cryptbuffer[ZipConstants.CRYPTO_HEADER_SIZE - 1] != (byte)((entry.DosTime >> 8) & 0xff)) {
						throw new ZipException("Invalid password");
					}
				}
					
				if (csize >= ZipConstants.CRYPTO_HEADER_SIZE) {
					csize -= ZipConstants.CRYPTO_HEADER_SIZE;
				}
			} 
			else {
				inputBuffer.CryptoTransform = null;
			}
			
			if (method == (int)CompressionMethod.Deflated && inputBuffer.Available > 0) {
				inputBuffer.SetInflaterInput(inf);
			}
			
			internalReader = new ReaderDelegate(BodyRead);
			return BodyRead(destination, offset, count);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:50,代码来源:ZipInputStream.cs

示例3: InitialRead

		/// <summary>
		/// Perform the initial read on an entry which may include 
		/// reading encryption headers and setting up inflation.
		/// </summary>
		/// <param name="destination">The destination to fill with data read.</param>
		/// <param name="offset">The offset to start reading at.</param>
		/// <param name="count">The maximum number of bytes to read.</param>
		/// <returns>The actual number of bytes read.</returns>
		int InitialRead(byte[] destination, int offset, int count)
		{
			if ( !CanDecompressEntry ) {
				throw new ZipException("Library cannot extract this entry. Version required is (" + entry.Version.ToString() + ")");
			}
			
			// Handle encryption if required.
			if (entry.IsCrypted) {
#if NETCF_1_0
				throw new ZipException("Encryption not supported for Compact Framework 1.0");
#else
				if (password == null) {
					throw new ZipException("No password set.");
				}
				
				// Generate and set crypto transform...
				PkzipClassicManaged managed = new PkzipClassicManaged();
				byte[] key = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(password));
				
				inputBuffer.CryptoTransform = managed.CreateDecryptor(key, null);
				
				byte[] cryptbuffer = new byte[ZipConstants.CryptoHeaderSize];
				inputBuffer.ReadClearTextBuffer(cryptbuffer, 0, ZipConstants.CryptoHeaderSize);

				if (cryptbuffer[ZipConstants.CryptoHeaderSize - 1] != entry.CryptoCheckValue) {
					throw new ZipException("Invalid password");
				}

				if (csize >= ZipConstants.CryptoHeaderSize) {
					csize -= ZipConstants.CryptoHeaderSize;
				}
				else if ( (entry.Flags & (int)GeneralBitFlags.Descriptor) == 0 ) {
					throw new ZipException(string.Format("Entry compressed size {0} too small for encryption", csize));
				}
#endif				
			} else {
#if !NETCF_1_0
				inputBuffer.CryptoTransform = null;
#endif				
			}

			if ((csize > 0) || ((flags & (int)GeneralBitFlags.Descriptor) != 0)) {
				if ((method == (int)CompressionMethod.Deflated) && (inputBuffer.Available > 0)) {
					inputBuffer.SetInflaterInput(inf);
				}

				internalReader = new ReadDataHandler(BodyRead);
				return BodyRead(destination, offset, count);
			}
			else {
				internalReader = new ReadDataHandler(ReadingNotAvailable);
				return 0;
			}
		}
开发者ID:nagyist,项目名称:SparkleDotNET,代码行数:62,代码来源:ZipInputStream.cs

示例4: CreateAndInitDecryptionStream

		Stream CreateAndInitDecryptionStream(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");
				}

				result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
				CheckClassicPassword(result, entry);
			}
			else {
				throw new ZipException("Decryption method not supported");
			}

			return result;
		}
开发者ID:fiftin,项目名称:SimpleUpdater,代码行数:22,代码来源:ZipFile.cs

示例5: InitialRead

        /// <summary>
        /// Perform the initial read on an entry which may include 
        /// reading encryption headers and setting up inflation.
        /// </summary>
        /// <param name="destination">The destination to fill with data read.</param>
        /// <param name="offset">The offset to start reading at.</param>
        /// <param name="count">The maximum number of bytes to read.</param>
        /// <returns>The actual number of bytes read.</returns>
        int InitialRead(byte[] destination, int offset, int count)
        {
            if ( !CanDecompressEntry ) {
                throw new ZipException("Library cannot extract this entry. Version required is (" + entry.Version.ToString() + ")");
            }

            // Handle encryption if required.
            if (entry.IsCrypted) {
            #if COMPACT_FRAMEWORK_V10
                throw new ZipException("Encyptiong not supported for Compact Framework 1.0");
            #else
                if (password == null) {
                    throw new ZipException("No password set.");
                }

                // Generate and set crypto transform...
                PkzipClassicManaged managed = new PkzipClassicManaged();
                byte[] key = PkzipClassic.GenerateKeys(Encoding.ASCII.GetBytes(password));

                inputBuffer.CryptoTransform = managed.CreateDecryptor(key, null);

                byte[] cryptbuffer = new byte[ZipConstants.CryptoHeaderSize];
                inputBuffer.ReadClearTextBuffer(cryptbuffer, 0, ZipConstants.CryptoHeaderSize);

                if (cryptbuffer[ZipConstants.CryptoHeaderSize - 1] != entry.CryptoCheckValue) {
                    throw new ZipException("Invalid password");
                }

                if (csize >= ZipConstants.CryptoHeaderSize) {
                    csize -= ZipConstants.CryptoHeaderSize;
                }
            #endif
            } else {
            #if !COMPACT_FRAMEWORK_V10
                inputBuffer.CryptoTransform = null;
            #endif
            }

            if ( (method == (int)CompressionMethod.Deflated) && (inputBuffer.Available > 0) ) {
                inputBuffer.SetInflaterInput(inf);
            }

            internalReader = new ReaderDelegate(BodyRead);
            return BodyRead(destination, offset, count);
        }
开发者ID:jeffboulanger,项目名称:cuodesktop,代码行数:53,代码来源:ZipInputStream.cs

示例6: InitialRead

 private int InitialRead(byte[] destination, int offset, int count)
 {
     if (!this.CanDecompressEntry)
     {
         throw new ZipException("Library cannot extract this entry. Version required is (" + this.entry.Version.ToString() + ")");
     }
     if (this.entry.IsCrypted)
     {
         if (this.password == null)
         {
             throw new ZipException("No password set.");
         }
         PkzipClassicManaged managed = new PkzipClassicManaged();
         byte[] rgbKey = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(this.password));
         base.inputBuffer.CryptoTransform = managed.CreateDecryptor(rgbKey, null);
         byte[] outBuffer = new byte[12];
         base.inputBuffer.ReadClearTextBuffer(outBuffer, 0, 12);
         if (outBuffer[11] != this.entry.CryptoCheckValue)
         {
             throw new ZipException("Invalid password");
         }
         if (base.csize < 12L)
         {
             if ((this.entry.Flags & 8) == 0)
             {
                 throw new ZipException(string.Format("Entry compressed size {0} too small for encryption", base.csize));
             }
         }
         else
         {
             base.csize -= 12L;
         }
     }
     else
     {
         base.inputBuffer.CryptoTransform = null;
     }
     if ((base.csize > 0L) || ((this.flags & 8) != 0))
     {
         if ((this.method == 8) && (base.inputBuffer.Available > 0))
         {
             base.inputBuffer.SetInflaterInput(base.inf);
         }
         this.internalReader = new ReadDataHandler(this.BodyRead);
         return this.BodyRead(destination, offset, count);
     }
     this.internalReader = new ReadDataHandler(this.ReadingNotAvailable);
     return 0;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:49,代码来源:ZipInputStream.cs

示例7: CreateAndInitDecryptionStream

 private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
 {
     CryptoStream classicCryptoStream = 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");
         }
         classicCryptoStream = new CryptoStream(baseStream, managed.CreateDecryptor(this.key, null), CryptoStreamMode.Read);
         CheckClassicPassword(classicCryptoStream, entry);
         return classicCryptoStream;
     }
     if (entry.Version != 0x33)
     {
         throw new ZipException("Decryption method not supported");
     }
     this.OnKeysRequired(entry.Name);
     if (!this.HaveKeys)
     {
         throw new ZipException("No password available for AES encrypted stream");
     }
     int aESSaltLen = entry.AESSaltLen;
     byte[] buffer = new byte[aESSaltLen];
     int num2 = baseStream.Read(buffer, 0, aESSaltLen);
     if (num2 != aESSaltLen)
     {
         throw new ZipException(string.Concat(new object[] { "AES Salt expected ", aESSaltLen, " got ", num2 }));
     }
     byte[] buffer2 = new byte[2];
     baseStream.Read(buffer2, 0, 2);
     int blockSize = entry.AESKeySize / 8;
     ZipAESTransform transform = new ZipAESTransform(this.rawPassword_, buffer, blockSize, false);
     byte[] pwdVerifier = transform.PwdVerifier;
     if ((pwdVerifier[0] != buffer2[0]) || (pwdVerifier[1] != buffer2[1]))
     {
         throw new Exception("Invalid password for AES");
     }
     return new ZipAESStream(baseStream, transform, CryptoStreamMode.Read);
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:42,代码来源:ZipFile.cs


注:本文中的ICSharpCode.SharpZipLib.Encryption.PkzipClassicManaged.CreateDecryptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。