本文整理汇总了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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}