Encrypt
Creates ciphertext that includes the values of an object's properties. Supports bulk operations.
You can encrypt:
- Objects stored in Vault by providing their ID.
- Fields not stored in Vault by providing a map of their properties and property values. However, fields must conform to the collection schema specified in the request.
- Ciphertext. This enables you to create a ciphertext including a subset of another ciphertext's properties or with a different encryption type or scope. To update the property values, use the update encrypted operation.
💡 For brevity, this guide uses the term object to refer to the content being encrypted.
If any request details are invalid, none of the objects are encrypted.
You can generate ciphertext for the encrypted object with a random initialization vector (randomized) or based on the collection name, input object, and scope (deterministic).
Using props, you can request that the ciphertext include a subset of the collection schema's properties.  However, if a property isn't present in the object or the property value is null, it is not included in the encrypted ciphertext. Also, if you want to include built-in properties, you must include them in props.
The role performing this operation must have both of these:
- The CapCryptoEncryptercapability.
- At least one allowing policy and no denying policies for the encryptoperation for each of the collection properties specified in the call.
See identity and access management for more information about how Vault uses capabilities to control access to operations and policies to control access to data.
Request
Header parameters
- X-Tenant-Id- array of strings- List of tenant IDs to enforce on the request. 
Path parameters
- collection- string required*- The name of a collection. 
Query parameters
- expiration_secs- string- Encrypted object expiration time in seconds. If not set, the default expiration time is used. See the - PVAULT_EXPIRATION_TOKENSvariable. If set to an empty value, the encrypted will be marked to not expire.
- adhoc_reason- string- An ad-hoc reason for accessing the Vault data. Required when - reasonis set to- Other.
- reason- string- Details of the reason for requesting the property. The default is set when no access reason is provided and PVAULT_SERVICE_FORCE_ACCESS_REASON is false. 
- custom_audit- string- Custom audit information to be included in the audit log. 
- reload_cache- boolean- Reloads the cache before the action. 
Request body
Details of the encryption request.
- application/json
- type- string- The type of the encryption: - randomized- generates a different randomized unpredictable, non-repeating ciphertext each time.
- deterministic- generates the ciphertext deterministically based on the collection name, input object, and scope. Defaults to- randomizedif not set.
 
- object- object required*- The input object, defined as one and only one of the following properties. - id: the ID of an object.
- fields: property values of an object.
- encrypted: an encrypted object.
- request_index: the index of the object in the request array.
 - In stateless mode, - idis not supported and either- fieldsor- encryptedmust be supplied.- id- string- The ID of an object. 
- fields- object- A list of maps of object properties and their values. Example- {
 "date_of_birth": "1993-02-22",
 "email": "patfar@example.com",
 "first_name": "Pat",
 "last_name": "Far",
 "phone_number": "+11011010101"
 }
- encrypted- object- An encrypted object. - ciphertext- string required*- The encrypted object base64 cipher text. 
- scope- string- The scope used to encrypt the object. By default, it uses the scope of the encrypted object. 
 
- request_index- integer- The index of the object in the request array. 
 Example- {
 "fields": {
 "first_name": "John",
 "email": "patfar@example.com"
 }
 }
- props- array of strings- A list of the properties to include in the encrypted object. If not provided, all properties are included, including the built-in properties, but omitting the object ID. Each string:- The name of a property. 
- scope- string- A classification for the encrypted object that is added to the ciphertext as associated data (AAD). An object encrypted with a scope can be decrypted only with the same scope. 
- tags- array of strings- Tags to attach to the metadata of the encrypted object. The maximum number of allowed tags is defined by the Each string:- PVAULT_DB_MAX_TOKEN_TAGSenvironment variable (default 10). Tags are not supported for the- deterministicencryption type.
[
  {
    "object": {
      "fields": {
        "email": "john@work.com",
        "phone_number": "555-555-5555"
      }
    },
    "props": [
      "phone_number",
      "email"
    ]
  }
]
Possible responses
- 200
- 400
- 401
- 403
- 404
- 405
- 409
- 410
- 500
- 503
The request is successful.
- application/json
- ciphertext- string required*- The encrypted object is a base64 ciphertext of the request fields and built-in fields such as timestamps and expiration time. It does not include the ID field. 
[
  {
    "ciphertext": "string"
  }
]
The request is invalid.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1001",
  "message": "The access reason is missing.",
  "context": {
    "reason": null
  }
}
Authentication credentials are incorrect or missing.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1005",
  "message": "The request is unauthorized.",
  "context": {}
}
The caller doesn't have the required access rights.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1007",
  "message": "The operation is forbidden due to missing capabilities.",
  "context": {
    "username": "WebServer"
  }
}
The collection or properties aren't found, or property values are invalid.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "objectid": "credit_cadr",
  "error_code": "PV3003",
  "message": "One or more values are invalid."
}
The operation is not allowed.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1026",
  "message": "The operation is not allowed in in-memory mode.",
  "context": {}
}
A conflict occurs.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV3218",
  "message": "Concurrent conflicting updates to the same object.",
  "context": {}
}
Access to a resource that is no longer available occurs.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1033",
  "message": "The resource is gone.",
  "context": {}
}
An error occurs on the server.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1000",
  "message": "Something went wrong",
  "context": {}
}
The service is unavailable.
- application/json
- context- object required*- The error context. Values of additional properties are stringsExample- {
 "objectid": "b56dd6aa-35f0-11ed-a261-0242ac120002"
 }
- error_code- string required*- The error code. 
- message- string required*- The error message. 
- error_url- string- The URL to the error documentation. 
{
  "error_code": "PV1009",
  "message": "The operation timed out on the server.",
  "context": {}
}
Path parameters
Query parameters
Headers
Request body
Code examples