Class ClientEncryption
- Namespace
- MongoDB.Driver.Encryption
- Assembly
- MongoDB.Driver.dll
Explicit client encryption.
- Inheritance
-
Client
Encryption
- Implements
- Inherited Members
Constructors
ClientEncryption(ClientEncryptionOptions)
Initializes a new instance of the Client
Parameters
clientEncryptionOptions
ClientEncryption Options The client encryption options.
Methods
AddAlternateKeyName(Guid, string, CancellationToken)
Adds an alternate key name to the keyAltNames array of the key document in the key vault collection with the given UUID (BSON binary subtype 0x04).
public BsonDocument AddAlternateKeyName(Guid id, string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
id
GuidThe id.
alternateKeyName
stringThe alternate key name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Document Returns the previous version of the key document.
AddAlternateKeyNameAsync(Guid, string, CancellationToken)
Adds an alternate key name to the keyAltNames array of the key document in the key vault collection with the given UUID (BSON binary subtype 0x04).
public Task<BsonDocument> AddAlternateKeyNameAsync(Guid id, string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
id
GuidThe id.
alternateKeyName
stringThe key alter name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Document > Returns the previous version of the key document.
CreateDataKey(string, DataKeyOptions, CancellationToken)
An alias function equivalent to createKey.
public Guid CreateDataKey(string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Parameters
kmsProvider
stringThe kms provider.
dataKeyOptions
DataKey Options The data key options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Guid
A data key.
CreateDataKeyAsync(string, DataKeyOptions, CancellationToken)
An alias function equivalent to createKey.
public Task<Guid> CreateDataKeyAsync(string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Parameters
kmsProvider
stringThe kms provider.
dataKeyOptions
DataKey Options The data key options.
cancellationToken
CancellationToken The cancellation token.
Returns
CreateEncryptedCollection(IMongoDatabase, string, CreateCollectionOptions, string, BsonDocument, CancellationToken)
Create encrypted collection.
public CreateEncryptedCollectionResult CreateEncryptedCollection(IMongoDatabase database, string collectionName, CreateCollectionOptions createCollectionOptions, string kmsProvider, BsonDocument masterKey, CancellationToken cancellationToken = default)
Parameters
database
IMongoDatabase The database.
collectionName
stringThe collection name.
createCollectionOptions
CreateCollection Options The create collection options.
kmsProvider
stringThe kms provider.
masterKey
BsonDocument The master key.
cancellationToken
CancellationToken The cancellation token.
Returns
- Create
Encrypted Collection Result The operation result.
Remarks
If EncryptionFields contains a keyId with a null value, a data key will be automatically generated and returned in Encrypted
CreateEncryptedCollection(IMongoDatabase, string, CreateCollectionOptions, string, DataKeyOptions, CancellationToken)
Create encrypted collection.
[Obsolete("Use the overload with masterKey instead.")]
public CreateEncryptedCollectionResult CreateEncryptedCollection(IMongoDatabase database, string collectionName, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Parameters
database
IMongoDatabase The database.
collectionName
stringThe collection name.
createCollectionOptions
CreateCollection Options The create collection options.
kmsProvider
stringThe kms provider.
dataKeyOptions
DataKey Options The datakey options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Create
Encrypted Collection Result The operation result.
Remarks
If EncryptionFields contains a keyId with a null value, a data key will be automatically generated and returned in Encrypted
CreateEncryptedCollectionAsync(IMongoDatabase, string, CreateCollectionOptions, string, BsonDocument, CancellationToken)
Create encrypted collection.
public Task<CreateEncryptedCollectionResult> CreateEncryptedCollectionAsync(IMongoDatabase database, string collectionName, CreateCollectionOptions createCollectionOptions, string kmsProvider, BsonDocument masterKey, CancellationToken cancellationToken = default)
Parameters
database
IMongoDatabase The database.
collectionName
stringThe collection name.
createCollectionOptions
CreateCollection Options The create collection options.
kmsProvider
stringThe kms provider.
masterKey
BsonDocument The master key.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Create
Encrypted >Collection Result The operation result.
Remarks
If EncryptionFields contains a keyId with a null value, a data key will be automatically generated and returned in Encrypted
CreateEncryptedCollectionAsync(IMongoDatabase, string, CreateCollectionOptions, string, DataKeyOptions, CancellationToken)
Create encrypted collection.
[Obsolete("Use the overload with masterKey instead.")]
public Task<CreateEncryptedCollectionResult> CreateEncryptedCollectionAsync(IMongoDatabase database, string collectionName, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Parameters
database
IMongoDatabase The database.
collectionName
stringThe collection name.
createCollectionOptions
CreateCollection Options The create collection options.
kmsProvider
stringThe kms provider.
dataKeyOptions
DataKey Options The datakey options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Create
Encrypted >Collection Result The operation result.
Remarks
If EncryptionFields contains a keyId with a null value, a data key will be automatically generated and returned in Encrypted
Decrypt(BsonBinaryData, CancellationToken)
Decrypts the specified value.
Parameters
value
BsonBinary Data The value.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Value The decrypted value.
DecryptAsync(BsonBinaryData, CancellationToken)
Decrypts the specified value.
public Task<BsonValue> DecryptAsync(BsonBinaryData value, CancellationToken cancellationToken = default)
Parameters
value
BsonBinary Data The value.
cancellationToken
CancellationToken The cancellation token.
Returns
DeleteKey(Guid, CancellationToken)
Removes the key document with the given UUID (BSON binary subtype 0x04) from the key vault collection.
Parameters
id
GuidThe id.
cancellationToken
CancellationToken The cancellation token.
Returns
- Delete
Result Returns the result of the internal deleteOne() operation on the key vault collection.
DeleteKeyAsync(Guid, CancellationToken)
Removes the key document with the given UUID (BSON binary subtype 0x04) from the key vault collection.
Parameters
id
GuidThe id.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Delete
Result > Returns the result of the internal deleteOne() operation on the key vault collection.
Dispose()
Encrypt(BsonValue, EncryptOptions, CancellationToken)
Encrypts the specified value.
public BsonBinaryData Encrypt(BsonValue value, EncryptOptions encryptOptions, CancellationToken cancellationToken = default)
Parameters
value
BsonValue The value.
encryptOptions
EncryptOptions The encrypt options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Binary Data The encrypted value.
EncryptAsync(BsonValue, EncryptOptions, CancellationToken)
Encrypts the specified value.
public Task<BsonBinaryData> EncryptAsync(BsonValue value, EncryptOptions encryptOptions, CancellationToken cancellationToken = default)
Parameters
value
BsonValue The value.
encryptOptions
EncryptOptions The encrypt options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Binary >Data The encrypted value.
EncryptExpression(BsonDocument, EncryptOptions, CancellationToken)
Encrypts a Match Expression or Aggregate Expression to query a range index.
public BsonDocument EncryptExpression(BsonDocument expression, EncryptOptions encryptOptions, CancellationToken cancellationToken = default)
Parameters
expression
BsonDocument The expression that is expected to be a BSON document of one of the following forms: 1. A Match Expression of this form: {$and: [{"field": {$gt: "value1"}}, {"field": {$lt: "value2" }}]} 2. An Aggregate Expression of this form: {$and: [{$gt: ["fieldpath", "value1"]}, {$lt: ["fieldpath", "value2"]}] $gt may also be $gte. $lt may also be $lte.
encryptOptions
EncryptOptions The encryption options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Document The encrypted expression.
Remarks
Only supported for queryType "rangePreview" The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.
EncryptExpressionAsync(BsonDocument, EncryptOptions, CancellationToken)
Encrypts a Match Expression or Aggregate Expression to query a range index.
public Task<BsonDocument> EncryptExpressionAsync(BsonDocument expression, EncryptOptions encryptOptions, CancellationToken cancellationToken = default)
Parameters
expression
BsonDocument The expression that is expected to be a BSON document of one of the following forms: 1. A Match Expression of this form: {$and: [{"field": {$gt: "value1"}}, {"field": {$lt: "value2" }}]} 2. An Aggregate Expression of this form: {$and: [{$gt: ["fieldpath", "value1"]}, {$lt: ["fieldpath", "value2"]}] $gt may also be $gte. $lt may also be $lte.
encryptOptions
EncryptOptions The encryption options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Document > the encrypted expression.
Remarks
Only supported for queryType "rangePreview" The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.
GetKey(Guid, CancellationToken)
Finds a single key document with the given UUID (BSON binary subtype 0x04).
Parameters
id
GuidThe id.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Document Returns the result of the internal find() operation on the key vault collection.
GetKeyAsync(Guid, CancellationToken)
Finds a single key document with the given UUID (BSON binary subtype 0x04).
Parameters
id
GuidThe id.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Document > Returns the result of the internal find() operation on the key vault collection.
GetKeyByAlternateKeyName(string, CancellationToken)
Finds a single key document with the given alter name.
public BsonDocument GetKeyByAlternateKeyName(string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
alternateKeyName
stringThe alternate key name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Document Returns a key document in the key vault collection with the given alternateKeyName.
GetKeyByAlternateKeyNameAsync(string, CancellationToken)
Finds a single key document with the given UUID (BSON binary subtype 0x04).
public Task<BsonDocument> GetKeyByAlternateKeyNameAsync(string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
alternateKeyName
stringThe alternate key name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Document > Returns a key document in the key vault collection with the given alternateKeyName.
GetKeys(CancellationToken)
Finds all documents in the key vault collection.
Parameters
cancellationToken
CancellationToken The cancellation token.
Returns
- IRead
Only <BsonList Document > Returns the result of the internal find() operation on the key vault collection.
GetKeysAsync(CancellationToken)
Finds all documents in the key vault collection.
public Task<IReadOnlyList<BsonDocument>> GetKeysAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<IRead
Only <BsonList Document >> Returns the result of the internal find() operation on the key vault collection.
RemoveAlternateKeyName(Guid, string, CancellationToken)
Removes an alternateKeyName from the keyAltNames array of the key document in the key vault collection with the given UUID (BSON binary subtype 0x04).
public BsonDocument RemoveAlternateKeyName(Guid id, string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
id
GuidThe id.
alternateKeyName
stringThe alternate key name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Bson
Document Returns the previous version of the key document.
RemoveAlternateKeyNameAsync(Guid, string, CancellationToken)
Removes an alternateKeyName from the keyAltNames array of the key document in the key vault collection with the given UUID (BSON binary subtype 0x04).
public Task<BsonDocument> RemoveAlternateKeyNameAsync(Guid id, string alternateKeyName, CancellationToken cancellationToken = default)
Parameters
id
GuidThe id.
alternateKeyName
stringThe alternate key name.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Bson
Document > Returns the previous version of the key document.
RewrapManyDataKey(FilterDefinition<BsonDocument>, RewrapManyDataKeyOptions, CancellationToken)
Decrypts multiple data keys and (re-)encrypts them with a new masterKey, or with their current masterKey if a new one is not given.
public RewrapManyDataKeyResult RewrapManyDataKey(FilterDefinition<BsonDocument> filter, RewrapManyDataKeyOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition <BsonDocument >The filter.
options
RewrapMany Data Key Options The options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Rewrap
Many Data Key Result The result.
RewrapManyDataKeyAsync(FilterDefinition<BsonDocument>, RewrapManyDataKeyOptions, CancellationToken)
Decrypts multiple data keys and (re-)encrypts them with a new masterKey, or with their current masterKey if a new one is not given.
public Task<RewrapManyDataKeyResult> RewrapManyDataKeyAsync(FilterDefinition<BsonDocument> filter, RewrapManyDataKeyOptions options, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition <BsonDocument >The filter.
options
RewrapMany Data Key Options The options.
cancellationToken
CancellationToken The cancellation token.
Returns
- Task<Rewrap
Many >Data Key Result The result.