/// <overloads>
        /// Writes an encrypted key to an output stream. This method is not intended to allow the keys to be
        /// moved from machine to machine.
        /// </overloads>
        /// <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="Stream"/> to which DPAPI-protected key is to be written.</param>
        /// <param name="encryptedKey">Encrypted key to be written to stream.</param>
        /// <param name="dpapiProtectionScope"><see cref="DataProtectionScope"/> used to protect the key on disk. </param>
        public static void Write(Stream outputStream,
                                 byte[] encryptedKey,
                                 DataProtectionScope dpapiProtectionScope)
        {
            ProtectedKey key = ProtectedKey.CreateFromEncryptedKey(encryptedKey, dpapiProtectionScope);

            Write(outputStream, key);
        }
예제 #2
0
 /// <summary>
 /// Reads a DPAPI-protected key from the given <see cref="Stream"/>.
 /// </summary>
 /// <param name="protectedKeyStream"><see cref="Stream"/> containing the DPAPI-protected key.</param>
 /// <param name="protectionScope"><see cref="DataProtectionScope"></see> used to decrypt the key read from the stream.</param>
 /// <returns>Key read from stream, encapsulated in a <see cref="ProtectedKey"></see>.</returns>
 public ProtectedKey Read(Stream protectedKeyStream, DataProtectionScope protectionScope)
 {
     ValidateKeyVersion(protectedKeyStream);
     return(ProtectedKey.CreateFromEncryptedKey(ReadEncryptedKey(protectedKeyStream), protectionScope));
 }