/// <summary> /// Create a volume key file using automatic key material generation. /// <para>The Key, and IV sets are generated automatically using the cipher description contained in the <see cref="CipherDescription"/>. /// This overload creates keying material using the seed and digest engines specified with the <see cref="KeyGenerator"/> class</para> /// </summary> /// /// <param name="Key">The <see cref="VolumeKey">VolumeKey</see> containing the cipher and key implementation details</param> /// <param name="SeedEngine">The <see cref="Prngs">Random Generator</see> used to create the stage I seed material during key generation.</param> /// <param name="HashEngine">The <see cref="Digests">Digest Engine</see> used in the stage II phase of key generation.</param> /// /// <exception cref="System.IO.FileLoadException">A key file exists at the path specified</exception> /// <exception cref="System.UnauthorizedAccessException">The key file path is read only</exception> public void Create(VolumeKey Key, Prngs SeedEngine = Prngs.CSPRng, Digests HashEngine = Digests.SHA512) { int ksize = Key.Count * (Key.Description.KeySize + Key.Description.IvSize); byte[] kdata; using (KeyGenerator keyGen = new KeyGenerator(SeedEngine, HashEngine)) kdata = keyGen.GetBytes(ksize); if (_keyStream == null) _keyStream = new FileStream(_keyPath, FileMode.Create, FileAccess.Write); byte[] hdr = Key.ToBytes(); _keyStream.Write(hdr, 0, hdr.Length); _keyStream.Write(kdata, 0, kdata.Length); }