Beispiel #1
0
        /// <summary>
        /// Serializes binary blocks into a file, possibly encrypted. Blocks are accessed in the order they were persisted.
        /// </summary>
        /// <param name="FileName">Name of file</param>
        /// <param name="CollectionName">Collection Name</param>
        /// <param name="Encrypted">If file is encrypted.</param>
        /// <param name="Provider">Provider of encryption keys.</param>
        public static async Task <SerialFile> Create(string FileName, string CollectionName, bool Encrypted, FilesProvider Provider)
        {
            SerialFile Result = new SerialFile(FileName, CollectionName, Encrypted);

            await GetKeys(Result, Provider);

            return(Result);
        }
Beispiel #2
0
        /// <summary>
        /// Gets keys for the serial file, or decendant.
        /// </summary>
        /// <param name="SerialFile">SerialFile reference, or decendant.</param>
        /// <param name="Provider">Provider of encryption keys.</param>
        protected static async Task GetKeys(SerialFile SerialFile, FilesProvider Provider)
        {
            if (SerialFile.encrypted)
            {
                SerialFile.aes           = Aes.Create();
                SerialFile.aes.BlockSize = 128;
                SerialFile.aes.KeySize   = 256;
                SerialFile.aes.Mode      = CipherMode.CBC;
                SerialFile.aes.Padding   = PaddingMode.None;

                KeyValuePair <byte[], byte[]> P = await Provider.GetKeys(SerialFile.fileName, SerialFile.fileExists);

                SerialFile.aesKey    = P.Key;
                SerialFile.ivSeed    = P.Value;
                SerialFile.ivSeedLen = SerialFile.ivSeed.Length;
            }
        }