/// <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); }
private void CheckNameConversion(string toCheck) { byte[] intermediate = ZipStrings.ConvertToArray(toCheck); string final = ZipStrings.ConvertToString(intermediate); Assert.AreEqual(toCheck, final, "Expected identical result"); }
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); }