protected override byte[] GetValidateErrInfo(byte[] headBytes) { int currentKey = BitConverter.ToInt32(headBytes, 0); string errRtf = CodySecurity_1.ValidateErrRtf.Replace("【CustomerKey】", currentKey.ToString()); return(SharpZipHelper.Compress(Encoding.UTF8.GetBytes(errRtf))); }
/// <summary> /// 压缩字节数组 /// </summary> public static byte[] Compress(byte[] bytes, int offset = 0) { using (MemoryStream ms = new MemoryStream()) { SharpZipHelper.Compress(ms, bytes, offset); return(ms.ToArray()); } }
public static byte[] CompressString(string str, Encoding encoding) { if (string.IsNullOrEmpty(str)) { return(new byte[0]); } return(SharpZipHelper.Compress(encoding.GetBytes(str))); }
/// <summary> /// 压缩字节数组 /// </summary> public static void Compress(string desFilePath, string tagetFilePath) { byte[] bytes = File.ReadAllBytes(desFilePath); if (File.Exists(tagetFilePath)) { throw new Exception("目标文件已存在!"); } using (FileStream fs = File.Create(tagetFilePath)) { SharpZipHelper.Compress(fs, bytes, 0); } }
public byte[] GetBinary() { if (this.IsCompress) { using (MemoryStream ms = new MemoryStream()) { ms.Write(BitConverter.GetBytes(this.IsCompress), 0, sizeof(bool)); byte[] compressBytes = SharpZipHelper.Compress(this.ContextStream.ToArray(), sizeof(bool)); ms.Write(compressBytes, 0, compressBytes.Length); return(ms.ToArray()); } } else { this.Write(this.IsCompress); return(this.ContextStream.ToArray()); } }
public static byte[] CompressAndEncrypt(byte[] bytes, int key) { return(CodySecurityHelper.Encrypt(SharpZipHelper.Compress(bytes), key)); }