コード例 #1
0
ファイル: Vault.cs プロジェクト: bmantoni/PasswordKeeper
        public void SaveVault(string filename)
        {
            /// Serialize
            MemoryStream    stream     = new MemoryStream();
            BinaryFormatter serializer = new BinaryFormatter();

            serializer.Serialize(stream, Entries);

            byte [] serializedVault = stream.ToArray();

            /// Encrypt
            IEncryptionUtility encryptor =
                EncryptionUtilityFactory.BuildEncryptionUtility();

            byte [] encryptedVault = encryptor.EncryptBinary(
                serializedVault, this.Password);

            /// Save encrypted contents to file, overwritting if exists
            FileStream outputFile = new FileStream(filename, FileMode.Create);

            outputFile.Write(encryptedVault, 0, encryptedVault.Length);
            outputFile.Close();

            isUnsavedChanges = false;
        }
コード例 #2
0
        public static IEncryptionUtility BuildEncryptionUtility()
        {
            Type t = Type.GetType(GetEncryptionUtilityClass());

            IEncryptionUtility util = ( IEncryptionUtility )
                                      Activator.CreateInstance(t);

            return(util);
        }
コード例 #3
0
 public PackageArgumentsService(
     IEncryptionUtility encryptionUtility,
     IFileSystem fileSystem,
     IChocolateyConfigurationProvider chocolateyConfigurationProvider,
     IDialogService dialogService)
 {
     _encryptionUtility = encryptionUtility;
     _fileSystem        = fileSystem;
     _chocolateyConfigurationProvider = chocolateyConfigurationProvider;
     _dialogService = dialogService;
 }
コード例 #4
0
ファイル: Vault.cs プロジェクト: bmantoni/PasswordKeeper
        public void OpenVault(string filename)
        {
            // open file
            FileStream inputFile = new FileStream(filename, FileMode.Open);

            byte [] encryptedVault = new byte [inputFile.Length];
            inputFile.Read(encryptedVault, 0, ( int )inputFile.Length);
            inputFile.Close();

            IEncryptionUtility decryptor =
                EncryptionUtilityFactory.BuildEncryptionUtility();

            byte [] serializedVault;

            try
            {
                /// Decrypt
                serializedVault = decryptor.DecryptBinary(
                    encryptedVault, this.Password);

                MemoryStream stream = new MemoryStream(serializedVault);

                // Deserialize
                BinaryFormatter deserializer = new BinaryFormatter();
                this.Entries = (ObservableCollection <Entry>)deserializer.Deserialize(stream);
            }
            catch (CryptographicException)
            {
                throw new VaultOpeningException(
                          "Unable to decrypt vault, check your password.");
            }
            catch (SerializationException)
            {
                throw new VaultOpeningException(
                          "Unable to open vault, check your password, " +
                          "or the file may be corrupt.");
            }
        }
コード例 #5
0
 /// <summary>
 ///     ''' Creates an instance with a specified key.
 ///     '''
 /// </summary>
 /// '''
 /// <param name="key">The key used for cryptographic functions, required 16 chars in length.</param>
 public SecureQueryString(string key)
 {
     _mEncryptionUtil = new EncryptionUtility(key);
 }