Beispiel #1
0
        public void InitializeFull(ConsoleEx consoleEx, HelixFileVersion fileVersion = null)
        {
            PreInitializationCheck();

            //Initialize Encr Directory
            consoleEx?.WriteLine(VerbosityLevel.Detailed, 0, "Initializing Encrypted Directory...");
            Header = DirectoryHeader.New();

            EncrDirectory.Create();
            if (WhatIf)
            {
                EncrDirectory.WhatIfAddFile(HelixConsts.HeaderFileName, 10);
            }
            else
            {
                Header.Save(EncrDirectory.PathFull(HelixConsts.HeaderFileName), DerivedBytesProvider, fileVersion);
                EncrDirectory.RefreshEntry(HelixConsts.HeaderFileName);
            }

            this.FileNameEncoder = new FileNameEncoder(Header.FileNameKey);
            consoleEx?.WriteLine(VerbosityLevel.Detailed, 1, "Encrypted Directory Initialized (" + Header.DirectoryId.Substring(0, 6) + "...)");


            InitializeDecr(consoleEx);
        }
Beispiel #2
0
        public static DirectoryHeader Load(string filePath, DerivedBytesProvider derivedBytesProvider)
        {
            DirectoryHeader directoryHeader = new DirectoryHeader();

            using Stream streamIn = File.OpenRead(filePath);
            using HelixFileDecryptor decryptor = new HelixFileDecryptor(streamIn);
            decryptor.Initialize(derivedBytesProvider);
            directoryHeader.FileVersion = decryptor.FileVersion;

            directoryHeader.Header      = decryptor.ReadHeader();
            directoryHeader.FileVersion = decryptor.FileVersion;

            var contentSerialized = decryptor.GetContentString();

            //var contentDeserialized = JsonConvert.DeserializeAnonymousType(contentSerialized, new { EncryptedFileNameSalt = new byte[] { } });
            JsonConvert.PopulateObject(contentSerialized, directoryHeader);

            if (!Regex.IsMatch(directoryHeader.DirectoryId, "^[0-9A-F]{32}$"))
            {
                throw new HelixException("Data curruption directory header, DirectoryId malformed");
            }
            if (directoryHeader.FileNameKey == null || directoryHeader.FileNameKey.Length != 32)
            {
                throw new HelixException("Data curruption directory header, FileNameKey missing or insufficient length");
            }

            return(directoryHeader);
        }
Beispiel #3
0
 public void OpenEncr(ConsoleEx consoleEx)
 {
     if (Header == null)
     {
         consoleEx?.WriteLine(VerbosityLevel.Detailed, 0, "Opening Encrypted Directory...");
         Header = DirectoryHeader.Load(EncrDirectory.PathFull(HelixConsts.HeaderFileName), DerivedBytesProvider);
         consoleEx?.WriteLine(VerbosityLevel.Detailed, 0, "Opened Encrypted Directory (" + Header.DirectoryId.Substring(0, 6) + "...)");
     }
     this.FileNameEncoder = new FileNameEncoder(Header.FileNameKey);
 }
Beispiel #4
0
        public static DirectoryHeader New(RandomNumberGenerator rng = null)
        {
            rng ??= RandomNumberGenerator.Create();

            DirectoryHeader directoryHeader =
                new DirectoryHeader
            {
                Header = new FileEntry {
                    FileName = "helix.hx"
                },

                FileNameKey = new byte[256 / 8]
            };

            rng.GetBytes(directoryHeader.FileNameKey);

            directoryHeader.DirectoryId = NewDirectoryId(rng);

            return(directoryHeader);
        }