コード例 #1
0
ファイル: XmlEncrypter.cs プロジェクト: lulzzz/Overseer-1
        /// <summary>
        /// Sets the pass phrase.
        /// </summary>
        /// <param name="passPhrase">The pass phrase.</param>
        /// <param name="salt">The salt.</param>
        public void SetPassPhrase(string passPhrase, byte[] salt)
        {
            Ensure.That(passPhrase).IsNotNullOrWhiteSpace();
            Ensure.That(salt).IsNotNull();
            Ensure.That(salt.Length % 16).Is(0);

            var passPhraseHash = HashUtility.GetHash(passPhrase, salt, 32);

            WritePassPhraseHash(passPhraseHash);

            HasPassPhrase = true;
        }
コード例 #2
0
ファイル: XmlEncrypter.cs プロジェクト: lulzzz/Overseer-1
        /// <summary>
        /// Writes the pass phrase hash.
        /// </summary>
        /// <param name="passPhraseHash">The pass phrase hash.</param>
        internal void WritePassPhraseHash(byte[] passPhraseHash)
        {
            var entropy = HashUtility.GetSalt(16);

            var cipherValue = _dataProtector.Protect(passPhraseHash, entropy);

            var registryValueBytes = new byte[16 + cipherValue.Length];

            Array.Copy(entropy, 0, registryValueBytes, 0, 16);
            Array.Copy(cipherValue, 0, registryValueBytes, 16, cipherValue.Length);

            var registryValue = Convert.ToBase64String(registryValueBytes);

            _registryStore.Write(KeyName, registryValue);
        }