示例#1
0
        /// <summary>
        /// The import key.
        /// </summary>
        /// <param name="protectionKeyContext">
        /// The protection key context.
        /// </param>
        /// <param name="keyData">
        /// The key data.
        /// </param>
        /// <param name="keyDataLength">
        /// The key data length.
        /// </param>
        /// <param name="flags">
        /// The flags.
        /// </param>
        /// <returns>
        /// The <see cref="KeyContext"/>.
        /// </returns>
        /// <exception cref="Win32Exception">
        /// </exception>
        private KeyContext ImportKey(KeyContext protectionKeyContext, byte[] keyData, int keyDataLength, int flags)
        {
            var protectionKeyHandler = IntPtr.Zero;

            if (protectionKeyContext != null)
            {
                protectionKeyHandler = protectionKeyContext.Handler;
            }

            var keyHandler = IntPtr.Zero;

            if (!CryptoApi.CryptImportKey(cspHandler, keyData, keyDataLength, protectionKeyHandler, flags, ref keyHandler))
            {
                throw new Win32Exception();
            }

            var keyContext = new KeyContext(keyHandler);

            return(keyContext);
        }