Пример #1
0
        /// <summary>
        /// Restores a cryptogrpahic key from a <see cref="T:System.IO.Stream" />. This method is intended for use in
        /// transferring a key between machines.
        /// </summary>
        /// <param name="inputStream"><see cref="T:System.IO.Stream" /> from which key is to be restored.</param>
        /// <param name="passphrase">User-provided passphrase used to encrypt the key in the arhive.</param>
        /// <param name="protectionScope"><see cref="T:System.Security.Cryptography.DataProtectionScope" /> used to protect the key on disk. </param>
        /// <returns>Key restored from stream, encapsulated in a <see cref="T:Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.ProtectedKey"></see>.</returns>
        public static ProtectedKey RestoreKey(Stream inputStream, string passphrase, DataProtectionScope protectionScope)
        {
            IKeyReader keyReader = new KeyReaderWriter();

            return(keyReader.Restore(inputStream, passphrase, protectionScope));
        }
Пример #2
0
        /// <summary>
        /// Archives a cryptographic key to a <see cref="T:System.IO.Stream" />. This method is intended for use in
        /// transferring a key between machines.
        /// </summary>
        /// <param name="outputStream"><see cref="T:System.IO.Stream" /> to which key is to be archived.</param>
        /// <param name="keyToArchive">Key to be archived.</param>
        /// <param name="passphrase">User-provided passphrase used to encrypt the key in the arhive.</param>
        public static void ArchiveKey(Stream outputStream, ProtectedKey keyToArchive, string passphrase)
        {
            IKeyWriter keyWriter = new KeyReaderWriter();

            keyWriter.Archive(outputStream, keyToArchive, passphrase);
        }
Пример #3
0
        /// <overloads>
        /// Reads an encrypted key from an input stream. This method is not intended to allow keys to be transferred
        /// from another machine.
        /// </overloads>
        /// <summary>
        /// Reads an encrypted key from an input stream. This method is not intended to allow keys to be transferred
        /// from another machine.
        /// </summary>
        /// <param name="inputStream"><see cref="T:System.IO.Stream" /> from which DPAPI-protected key is to be read.</param>
        /// <param name="dpapiProtectionScope"><see cref="T:System.Security.Cryptography.DataProtectionScope" /> used to protect the key on disk. </param>
        /// <returns>Key read from stream, encapsulated in a <see cref="T:Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.ProtectedKey"></see>.</returns>
        public static ProtectedKey Read(Stream inputStream, DataProtectionScope dpapiProtectionScope)
        {
            IKeyReader keyReader = new KeyReaderWriter();

            return(keyReader.Read(inputStream, dpapiProtectionScope));
        }
Пример #4
0
        /// <summary>
        /// Writes an encrypted key to an output stream. This method is not intended to allow the keys to be
        /// moved from machine to machine.
        /// </summary>
        /// <param name="outputStream"><see cref="T:System.IO.Stream" /> to which DPAPI-protected key is to be written.</param>
        /// <param name="key">Encrypted key to be written to stream.</param>
        public static void Write(Stream outputStream, ProtectedKey key)
        {
            IKeyWriter keyWriter = new KeyReaderWriter();

            keyWriter.Write(outputStream, key);
        }