namespace com.hitrust.util.Encryption
|
|
{
|
|
using com.hitrust.util.Checksums;
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
|
|
public abstract class PkzipClassic : SymmetricAlgorithm
|
|
{
|
|
protected PkzipClassic()
|
|
{
|
|
}
|
|
|
|
public static byte[] GenerateKeys(byte[] seed)
|
|
{
|
|
if (seed == null)
|
|
{
|
|
throw new ArgumentNullException("seed");
|
|
}
|
|
if (seed.Length == 0)
|
|
{
|
|
throw new ArgumentException("Length is zero", "seed");
|
|
}
|
|
uint[] newKeys = new uint[] { 0x12345678, 0x23456789, 0x34567890 };
|
|
for (int i = 0; i < seed.Length; i++)
|
|
{
|
|
newKeys[0] = Crc32.ComputeCrc32(newKeys[0], seed[i]);
|
|
newKeys[1] += (byte) newKeys[0];
|
|
newKeys[1] = (newKeys[1] * 0x8088405) + 1;
|
|
newKeys[2] = Crc32.ComputeCrc32(newKeys[2], (byte) (newKeys[1] >> 0x18));
|
|
}
|
|
return new byte[] { ((byte) (newKeys[0] & 0xff)), ((byte) ((newKeys[0] >> 8) & 0xff)), ((byte) ((newKeys[0] >> 0x10) & 0xff)), ((byte) ((newKeys[0] >> 0x18) & 0xff)), ((byte) (newKeys[1] & 0xff)), ((byte) ((newKeys[1] >> 8) & 0xff)), ((byte) ((newKeys[1] >> 0x10) & 0xff)), ((byte) ((newKeys[1] >> 0x18) & 0xff)), ((byte) (newKeys[2] & 0xff)), ((byte) ((newKeys[2] >> 8) & 0xff)), ((byte) ((newKeys[2] >> 0x10) & 0xff)), ((byte) ((newKeys[2] >> 0x18) & 0xff)) };
|
|
}
|
|
}
|
|
}
|
|
|