/// <summary> /// protected virtual void WriteFile(string secretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType) /// </summary> /// <param name="secretKey"></param> /// <param name="data"></param> /// <param name="version"></param> /// <param name="encryptor"></param> /// <param name="algType"></param> /// <param name="algKeyType"></param> protected virtual void WriteFile(string secretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType) { using (FileStream f = new FileStream(_fileName, FileMode.Create)) { using (BinaryWriter w = new BinaryWriter(f)) { try { w.Write((Int16)5); w.Write((byte)version); w.Write(Convert.ToByte((int)algType)); w.Write(Convert.ToByte((int)algKeyType)); w.Write(encryptor.ObjectCryptography(data, TransformType.ENCRYPT)); w.Flush(); } catch (IOException e) { throw e; } finally { w.Close(); f.Close(); } } } }
/// <summary> /// protected virtual byte[] WriteMenoryStream(string seretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType) /// </summary> /// <param name="seretKey"></param> /// <param name="data"></param> /// <param name="version"></param> /// <param name="encryptor"></param> /// <param name="algType"></param> /// <param name="algKeyType"></param> /// <returns></returns> protected virtual byte[] WriteMenoryStream(string seretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType) { byte[] value = null; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter w = new BinaryWriter(ms)) { try { w.Write((Int16)5); w.Write((byte)version); w.Write(Convert.ToByte((int)algType)); w.Write(Convert.ToByte((int)algKeyType)); w.Write(encryptor.ObjectCryptography(data, TransformType.ENCRYPT)); w.Flush(); value = ms.ToArray(); } catch (Exception e) { throw e; } finally { w.Close(); ms.Close(); } } } return(value); }