Beispiel #1
0
        /// <summary>
        /// Encrypt a PacCredentialData instance. The encrypted data
        /// can be accessed from SerializedData property.
        /// </summary>
        /// <param name="credentialData">The _PAC_CREDENTIAL_DATA instance to be encrypted.</param>
        /// <param name="key">The encrypt key.</param>
        public void Encrypt(_PAC_CREDENTIAL_DATA credentialData, byte[] key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            byte[] plain = null;
            using (SafeIntPtr ptr = TypeMarshal.ToIntPtr(credentialData))
            {
                plain = PacUtility.NdrMarshal(ptr, FormatString.OffsetCredentialData);
            }
            NativePacCredentialInfo.SerializedData = Encrypt(key, plain, NativePacCredentialInfo.EncryptionType);
        }
        /// <summary>
        /// Creates an PacCredentialInfo instance using the specified Type and credentials.
        /// </summary>
        /// <param name="type">Encryption Type.</param>
        /// <param name="key">The encrypt key.</param>
        /// <param name="credentials">A list of security package supplemental credentials.</param>
        /// <returns>The created PacCredentialInfo instance.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Type is not defined.</exception>
        public static PacCredentialInfo CreateCredentialInfoBuffer(
            EncryptionType_Values type,
            byte[] key,
            _SECPKG_SUPPLEMENTAL_CRED[] credentials)
        {
            PacCredentialInfo credentialInfo = new PacCredentialInfo();

            credentialInfo.NativePacCredentialInfo.EncryptionType = type;

            _PAC_CREDENTIAL_DATA credentialData = new _PAC_CREDENTIAL_DATA();

            credentialData.CredentialCount = (uint)credentials.Length;
            credentialData.Credentials     = credentials;

            credentialInfo.Encrypt(credentialData, key);

            return(credentialInfo);
        }
        /// <summary>
        /// Encrypt a PacCredentialData instance. The encrypted data
        /// can be accessed from SerializedData property.
        /// </summary>
        /// <param name="credentialData">The _PAC_CREDENTIAL_DATA instance to be encrypted.</param>
        /// <param name="key">The encrypt key.</param>
        public void Encrypt(_PAC_CREDENTIAL_DATA credentialData, byte[] key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            byte[] plain = null;
            using (SafeIntPtr ptr = TypeMarshal.ToIntPtr(credentialData))
            {
                plain = PacUtility.NdrMarshal(ptr, FormatString.OffsetCredentialData);
            }
            NativePacCredentialInfo.SerializedData = Encrypt(key, plain, NativePacCredentialInfo.EncryptionType);
        }