use of com.mongodb.crypt.capi.MongoCryptException in project mongo-java-driver by mongodb.
the class Crypt method encryptExplicitly.
/**
* Encrypt the given value with the given options
*
* @param value the value to encrypt
* @param options the options
* @return the encrypted value
*/
BsonBinary encryptExplicitly(final BsonValue value, final EncryptOptions options) {
notNull("value", value);
notNull("options", options);
try {
MongoExplicitEncryptOptions.Builder encryptOptionsBuilder = MongoExplicitEncryptOptions.builder().algorithm(options.getAlgorithm());
if (options.getKeyId() != null) {
encryptOptionsBuilder.keyId(options.getKeyId());
}
if (options.getKeyAltName() != null) {
encryptOptionsBuilder.keyAltName(options.getKeyAltName());
}
MongoCryptContext encryptionContext = mongoCrypt.createExplicitEncryptionContext(new BsonDocument("v", value), encryptOptionsBuilder.build());
try {
return executeStateMachine(encryptionContext, null).getBinary("v");
} finally {
encryptionContext.close();
}
} catch (MongoCryptException e) {
throw wrapInClientException(e);
}
}
use of com.mongodb.crypt.capi.MongoCryptException in project mongo-java-driver by mongodb.
the class Crypt method createDataKey.
/**
* Create a data key.
*
* @param kmsProvider the KMS provider to create the data key for
* @param options the data key options
* @return the document representing the data key to be added to the key vault
*/
BsonDocument createDataKey(final String kmsProvider, final DataKeyOptions options) {
notNull("kmsProvider", kmsProvider);
notNull("options", options);
try {
MongoCryptContext dataKeyCreationContext = mongoCrypt.createDataKeyContext(kmsProvider, MongoDataKeyOptions.builder().keyAltNames(options.getKeyAltNames()).masterKey(options.getMasterKey()).build());
try {
return executeStateMachine(dataKeyCreationContext, null);
} finally {
dataKeyCreationContext.close();
}
} catch (MongoCryptException e) {
throw wrapInClientException(e);
}
}
use of com.mongodb.crypt.capi.MongoCryptException in project mongo-java-driver by mongodb.
the class Crypt method encrypt.
/**
* Encrypt the given command
*
* @param databaseName the namespace
* @param command the unencrypted command
* @return the encrypted command
*/
public RawBsonDocument encrypt(final String databaseName, final RawBsonDocument command) {
notNull("databaseName", databaseName);
notNull("command", command);
if (bypassAutoEncryption) {
return command;
}
try {
MongoCryptContext encryptionContext = mongoCrypt.createEncryptionContext(databaseName, command);
try {
return executeStateMachine(encryptionContext, databaseName);
} finally {
encryptionContext.close();
}
} catch (MongoCryptException e) {
throw wrapInClientException(e);
}
}
Aggregations