/// <summary> /// Starts the decryption context. /// </summary> /// <param name="buffer">The bson document to decrypt.</param> /// <returns>A decryption context</returns> public CryptContext StartDecryptionContext(byte[] buffer) { ContextSafeHandle handle = Library.mongocrypt_ctx_new(_handle); GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); unsafe { fixed (byte* p = buffer) { IntPtr ptr = (IntPtr)p; using (PinnedBinary pinned = new PinnedBinary(ptr, (uint)buffer.Length)) { handle.Check(_status, Library.mongocrypt_ctx_decrypt_init(handle, pinned.Handle)); } } } return new CryptContext(handle); }