コード例 #1
0
        /// <summary>
        /// Starts an explicit encryption context.
        /// </summary>
        /// <param name="keyAltName">The alternative key name.</param>
        /// <param name="encryptionAlgorithm">The algorithm.</param>
        /// <param name="message">The BSON message.</param>
        /// <returns>A encryption context. </returns>
        public CryptContext StartExplicitEncryptionContextWithKeyAltName(byte[] keyAltName, EncryptionAlgorithm encryptionAlgorithm, byte[] message)
        {
            ContextSafeHandle handle = Library.mongocrypt_ctx_new(_handle);

            unsafe
            {
                fixed(byte *p = keyAltName)
                {
                    IntPtr ptr = (IntPtr)p;

                    using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)keyAltName.Length))
                    {
                        handle.Check(_status, Library.mongocrypt_ctx_setopt_key_alt_name(handle, pinned.Handle));
                    }
                }
            }

            handle.Check(_status, Library.mongocrypt_ctx_setopt_algorithm(handle, Helpers.EncryptionAlgorithmToString(encryptionAlgorithm), -1));

            unsafe
            {
                fixed(byte *p = message)
                {
                    IntPtr ptr = (IntPtr)p;

                    using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)message.Length))
                    {
                        handle.Check(_status, Library.mongocrypt_ctx_explicit_encrypt_init(handle, pinned.Handle));
                    }
                }
            }

            return(new CryptContext(handle));
        }
コード例 #2
0
        internal static void SetAlternateKeyNames(this IKmsKeyId kmsKeyId, ContextSafeHandle context, Status status)
        {
            foreach (var alternateKeyName in kmsKeyId.AlternateKeyNameBsonDocuments)
            {
                unsafe
                {
                    fixed(byte *p = alternateKeyName)
                    {
                        IntPtr ptr = (IntPtr)p;

                        using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)alternateKeyName.Length))
                        {
                            context.Check(status, Library.mongocrypt_ctx_setopt_key_alt_name(context, pinned.Handle));
                        }
                    }
                }
            }
        }
コード例 #3
0
        // internal methods
        internal void SetAlternateKeyNames(ContextSafeHandle context, Status status)
        {
            foreach (var alternateKeyNameBytes in _alternateKeyNameBytes)
            {
                unsafe
                {
                    fixed(byte *p = alternateKeyNameBytes)
                    {
                        IntPtr ptr = (IntPtr)p;

                        using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)alternateKeyNameBytes.Length))
                        {
                            context.Check(status, Library.mongocrypt_ctx_setopt_key_alt_name(context, pinned.Handle));
                        }
                    }
                }
            }
        }