Beispiel #1
0
        /// <summary>
        /// Decrypts the specified arguments.
        /// </summary>
        /// <param name="module">The module.</param>
        private static void Decrypt(IEncryptionModule module, string hash)
        {
            if (module == default(IEncryptionModule))
            {
                return;
            }

            if (module.IsDecryptable)
            {
                var text = module.Decrypt(hash);
                ConsoleHelper.WriteMessage(text);
            }
            else
            {
                ConsoleHelper.WriteMessage("Module does not support decrypting.");
            }
        }
Beispiel #2
0
        /**
         * create header for encrypted file
         *
         * @param array headerData
         * @param IEncryptionModule encryptionModule
         * @return string
         * @throws EncryptionHeaderToLargeException if header has to many arguments
         * @throws EncryptionHeaderKeyExistsException if header key is already in use
         */
        public string createHeader(IDictionary <string, string> headerData, IEncryptionModule encryptionModule)
        {
            var header = HEADER_START + ":" + HEADER_ENCRYPTION_MODULE_KEY + ":" + encryptionModule.getId() + ":";

            foreach (var headerKeyPair in headerData)
            {
                if (this.ocHeaderKeys.Contains(headerKeyPair.Key))
                {
                    throw new EncryptionHeaderKeyExistsException();
                }

                header += headerKeyPair.Key + ":" + headerKeyPair.Value + ":";
            }

            header += HEADER_END;

            if (header.Length > this.getHeaderSize())
            {
                throw new EncryptionHeaderToLargeException();
            }
            var paddedHeader = header.PadRight(this.headerSize, HEADER_PADDING_CHAR)

                               return(paddedHeader);
        }
Beispiel #3
0
        /// <summary>
        /// Encrypts the specified arguments.
        /// </summary>
        /// <param name="module">The module.</param>
        private static void Encrypt(IEncryptionModule module, string text)
        {
            if (module == default(IEncryptionModule))
            {
                return;
            }

            var hash = module.Encrypt(text);
            ConsoleHelper.WriteMessage(hash);
        }
Beispiel #4
0
        /// <summary>
        /// Validates the specified arguments.
        /// </summary>
        /// <param name="module">The module.</param>
        private static void Validate(IEncryptionModule module, string text, string hash)
        {
            if (module == default(IEncryptionModule))
            {
                return;
            }

            var result = module.Validate(text, hash);
            ConsoleHelper.WriteMessage(result.ToString());
        }
Beispiel #5
0
 /// <summary>
 /// Handles the SelectedIndexChanged event of the EncryptionTypeLst control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void EncryptionTypeLst_SelectedIndexChanged(object sender, EventArgs e)
 {
     var type = (EncryptionType)Enum.Parse(typeof(EncryptionType), EncryptionTypeLst.Text, true);
     Module = HaxxorFactory.GetByType(type);
     UpdateResult();
 }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IcarusCollection" /> class.
        /// </summary>
        /// <param name="dataStoreLocation">The data store location.</param>
        /// <param name="collectionName">Name of the collection.</param>
        /// <param name="isAccessEveryone">if set to <c>true</c> [Icarus data is accessible by everyone].</param>
        /// <param name="isEncryted">if set to <c>true</c> the collection will be encrypted.</param>
        /// <param name="encryptionKey">The optional encryption key. If not supplied a default will be used.</param>
        public IcarusCollection(string dataStoreLocation, string collectionName, bool isAccessEveryone = false, bool isEncryted = false)
        {
            var path = string.Empty;

            IsEncryted        = isEncryted;
            _encryptionModule = HaxxorFactory.GetByType(EncryptionType.AES256);

            IsAccessEveryone = isAccessEveryone;

            // Create collection if it doesn't exist
            if (!Exists(dataStoreLocation, collectionName, out path))
            {
                using (var file = File.CreateText(path))
                {
                    file.WriteLine(IsEncryted ? _encryptionModule.Encrypt(NewEmptyFile, false) : NewEmptyFile);
                }
            }

            // toggle access control to everyone
            try
            {
                var security = File.GetAccessControl(path);
                var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                var rule     = new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow);

                if (IsAccessEveryone)
                {
                    security.AddAccessRule(rule);
                }
                else
                {
                    security.RemoveAccessRule(rule);
                }

                File.SetAccessControl(path, security);
            }
            catch (UnauthorizedAccessException)
            {
                // Not ideal, and needs logging, but if we fail to set the access controls we shouldn't bomb out
            }

            // set collection locations
            CachingEnabled     = true;
            CollectionName     = collectionName;
            CollectionLocation = path;
            DataStoreLocation  = dataStoreLocation;

            // Load contents of file
            LoadJsonData();

            // Set next primary ID
            if (_json.HasValues)
            {
                NextPrimaryId = _json.Value <long>(NextPrimaryIdKey);
            }
            else
            {
                NextPrimaryId = DefaultNextPrimaryId;
                _json.Add(DataKey, new JArray());
            }

            // Indexes
            _primaryIndex = new Dictionary <long, JToken>(10);
        }