

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Enkripsi yang dapat dicari di DynamoDB
<a name="ddb-searchable-encryption"></a>

Untuk mengonfigurasi tabel Amazon DynamoDB Anda untuk enkripsi yang dapat dicari, Anda harus menggunakan AWS KMS keyring [Hierarkis](use-hierarchical-keyring.md) untuk menghasilkan, mengenkripsi, dan mendekripsi kunci data yang digunakan untuk melindungi item Anda. Anda juga harus menyertakan konfigurasi enkripsi tabel Anda. [`SearchConfig`](ddb-net-using.md#ddb-net-search-config) 

**catatan**  
Jika Anda menggunakan pustaka enkripsi sisi klien Java untuk DynamoDB, Anda harus menggunakan SDK Enkripsi AWS Database tingkat rendah untuk DynamoDB API untuk mengenkripsi, menandatangani, memverifikasi, dan mendekripsi item tabel Anda. DynamoDB Enhanced Client dan `DynamoDBItemEncryptor` level yang lebih rendah tidak mendukung enkripsi yang dapat dicari.

**Topics**
+ [Mengkonfigurasi indeks sekunder dengan beacon](#ddb-beacon-indexes)
+ [Menguji output suar](#ddb-beacon-testing)

## Mengkonfigurasi indeks sekunder dengan beacon
<a name="ddb-beacon-indexes"></a>

Setelah [Anda mengkonfigurasi beacon](configure-beacons.md) Anda, Anda harus mengkonfigurasi indeks sekunder yang mencerminkan setiap suar sebelum Anda dapat mencari pada atribut terenkripsi.

Saat Anda mengonfigurasi suar standar atau gabungan, SDK Enkripsi AWS Database menambahkan `aws_dbe_b_` awalan ke nama suar sehingga server dapat dengan mudah mengidentifikasi beacon. Misalnya, jika Anda menamai suar majemuk`compoundBeacon`, nama suar lengkapnya sebenarnya. `aws_dbe_b_compoundBeacon` Jika Anda ingin mengonfigurasi [indeks sekunder](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html) yang menyertakan suar standar atau majemuk, Anda harus menyertakan `aws_dbe_b_` awalan saat mengidentifikasi nama suar.

**Partisi dan sortir kunci**  
Anda tidak dapat mengenkripsi nilai kunci primer. Kunci partisi dan sortir Anda harus ditandatangani. Nilai kunci primer Anda tidak bisa menjadi suar standar atau majemuk.  
Nilai kunci utama Anda harus`SIGN_ONLY`, kecuali Anda menentukan `SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT` atribut apa pun, maka atribut partisi dan sortir juga harus`SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT`.  
Nilai kunci utama Anda dapat ditandatangani beacon. Jika Anda mengonfigurasi beacon bertanda tangan yang berbeda untuk setiap nilai kunci utama, Anda harus menentukan nama atribut yang mengidentifikasi nilai kunci primer sebagai nama suar yang ditandatangani. Namun, SDK Enkripsi AWS Database tidak menambahkan `aws_dbe_b_` awalan ke beacon yang ditandatangani. Bahkan jika Anda mengonfigurasi beacon bertanda tangan yang berbeda untuk nilai kunci utama Anda, Anda hanya perlu menentukan nama atribut untuk nilai kunci primer saat Anda mengonfigurasi indeks sekunder.

**Indeks sekunder lokal**  
Kunci sortir untuk [indeks sekunder lokal](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html) dapat berupa suar.  
Jika Anda menentukan suar untuk kunci sortir, tipenya harus String. Jika Anda menentukan standar atau suar majemuk untuk kunci sortir, Anda harus menyertakan `aws_dbe_b_` awalan saat Anda menentukan nama suar. Jika Anda menentukan suar yang ditandatangani, tentukan nama suar tanpa awalan apa pun.

**Indeks sekunder global**  
Kunci partisi dan sortir untuk [indeks sekunder global](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html) dapat berupa beacon.  
Jika Anda menentukan suar untuk partisi atau kunci sortir, jenisnya harus String. Jika Anda menentukan standar atau suar majemuk untuk kunci sortir, Anda harus menyertakan `aws_dbe_b_` awalan saat Anda menentukan nama suar. Jika Anda menentukan suar yang ditandatangani, tentukan nama suar tanpa awalan apa pun.

**Proyeksi atribut**  
[Proyeksi](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Projections) adalah kumpulan atribut yang disalin dari tabel ke indeks sekunder. Kunci partisi dan kunci urutan tabel selalu diproyeksikan ke dalam indeks; Anda dapat memproyeksikan atribut lain untuk mendukung persyaratan kueri aplikasi Anda. DynamoDB menyediakan tiga opsi berbeda untuk proyeksi `KEYS_ONLY` atribut:,, dan. `INCLUDE` `ALL`  
Jika Anda menggunakan proyeksi atribut INCLUDE untuk mencari pada suar, Anda harus menentukan nama untuk semua atribut yang suar dibangun dari dan nama suar dengan awalan. `aws_dbe_b_` Misalnya, jika Anda mengkonfigurasi suar majemuk,`compoundBeacon`, dari,`field1`, dan `field2``field3`, Anda harus menentukan`aws_dbe_b_compoundBeacon`,, `field1``field2`, dan `field3` dalam proyeksi.  
Indeks sekunder global hanya dapat menggunakan atribut yang ditentukan secara eksplisit dalam proyeksi, tetapi indeks sekunder lokal dapat menggunakan atribut apa pun.

## Menguji output suar
<a name="ddb-beacon-testing"></a>

Jika Anda [mengonfigurasi suar majemuk](configure-beacons.md#config-compound-beacons) atau membuat beacon menggunakan [bidang virtual](configure-beacons.md#create-virtual-field), sebaiknya verifikasi bahwa beacon ini menghasilkan output yang diharapkan sebelum mengisi tabel DynamoDB Anda.

 AWS Database Encryption SDK menyediakan `DynamoDbEncryptionTransforms` layanan untuk membantu Anda memecahkan masalah bidang virtual dan output suar gabungan.

### Menguji bidang virtual
<a name="ddb-beacon-testing-virtual-field"></a>

Cuplikan berikut membuat item pengujian, mendefinisikan `DynamoDbEncryptionTransforms` layanan dengan [konfigurasi enkripsi tabel DynamoDB](ddb-java-using.md#ddb-config-encrypt), dan menunjukkan cara menggunakan `ResolveAttributes` untuk memverifikasi bahwa bidang virtual menghasilkan output yang diharapkan.

------
#### [ Java ]

**Lihat contoh kode lengkapnya**: [VirtualBeaconSearchableEncryptionExample.java](https://github.com/aws/aws-database-encryption-sdk-dynamodb//blob/main/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/VirtualBeaconSearchableEncryptionExample.java) 

```
// Create test items
final PutItemRequest itemWithHasTestResultPutRequest = PutItemRequest.builder()
    .tableName(ddbTableName)
    .item(itemWithHasTestResult)
    .build();

final PutItemResponse itemWithHasTestResultPutResponse = ddb.putItem(itemWithHasTestResultPutRequest);

final PutItemRequest itemWithNoHasTestResultPutRequest = PutItemRequest.builder()
    .tableName(ddbTableName)
    .item(itemWithNoHasTestResult)
    .build();
    
final PutItemResponse itemWithNoHasTestResultPutResponse = ddb.putItem(itemWithNoHasTestResultPutRequest);    

// Define the DynamoDbEncryptionTransforms service
final DynamoDbEncryptionTransforms trans = DynamoDbEncryptionTransforms.builder()
    .DynamoDbTablesEncryptionConfig(encryptionConfig).build();

// Verify configuration
final ResolveAttributesInput resolveInput = ResolveAttributesInput.builder()
    .TableName(ddbTableName)
    .Item(itemWithHasTestResult)
    .Version(1)
    .build();
final ResolveAttributesOutput resolveOutput = trans.ResolveAttributes(resolveInput);

// Verify that VirtualFields has the expected value
Map<String, String> vf = new HashMap<>();
vf.put("stateAndHasTestResult", "CAt");
assert resolveOutput.VirtualFields().equals(vf);
```

------
#### [ C\$1 / .NET ]

**Lihat contoh kode lengkapnya**: [VirtualBeaconSearchableEncryptionExample.cs.](https://github.com/aws/aws-database-encryption-sdk-dynamodb/tree/main/Examples/runtimes/net/src/searchableencryption/VirtualBeaconSearchableEncryptionExample.cs)

```
 // Create item with hasTestResult=true
var itemWithHasTestResult = new Dictionary<String, AttributeValue>
{
    ["customer_id"] = new AttributeValue("ABC-123"),
    ["create_time"] = new AttributeValue { N = "1681495205" },
    ["state"] = new AttributeValue("CA"),
    ["hasTestResult"] = new AttributeValue { BOOL = true }
};

// Create item with hasTestResult=false
var itemWithNoHasTestResult = new Dictionary<String, AttributeValue>
{
    ["customer_id"] = new AttributeValue("DEF-456"),
    ["create_time"] = new AttributeValue { N = "1681495205" },
    ["state"] = new AttributeValue("CA"),
    ["hasTestResult"] = new AttributeValue { BOOL = false }
};

// Define the DynamoDbEncryptionTransforms service
var trans = new DynamoDbEncryptionTransforms(encryptionConfig);

// Verify configuration
var resolveInput = new ResolveAttributesInput
{
    TableName = ddbTableName,
    Item = itemWithHasTestResult,
    Version = 1
};
var resolveOutput = trans.ResolveAttributes(resolveInput);

// Verify that VirtualFields has the expected value
Debug.Assert(resolveOutput.VirtualFields.Count == 1);
Debug.Assert(resolveOutput.VirtualFields["stateAndHasTestResult"] == "CAt");
```

------
#### [ Rust ]

**Lihat contoh kode lengkap: [virtual\$1beacon\$1searchable\$1encryption.rs](https://github.com/aws/aws-database-encryption-sdk-dynamodb/blob/main/releases/rust/db_esdk/examples/searchableencryption/virtual_beacon_searchable_encryption.rs)**.

```
// Create item with hasTestResult=true
let item_with_has_test_result = HashMap::from([
    (
        "customer_id".to_string(),
        AttributeValue::S("ABC-123".to_string()),
    ),
    (
        "create_time".to_string(),
        AttributeValue::N("1681495205".to_string()),
    ),
    ("state".to_string(), AttributeValue::S("CA".to_string())),
    ("hasTestResult".to_string(), AttributeValue::Bool(true)),
]);

// Create item with hasTestResult=false
let item_with_no_has_test_result = HashMap::from([
    (
        "customer_id".to_string(),
        AttributeValue::S("DEF-456".to_string()),
    ),
    (
        "create_time".to_string(),
        AttributeValue::N("1681495205".to_string()),
    ),
    ("state".to_string(), AttributeValue::S("CA".to_string())),
    ("hasTestResult".to_string(), AttributeValue::Bool(false)),
]);

// Define the transform service
let trans = transform_client::Client::from_conf(encryption_config.clone())?;

// Verify the configuration 
let resolve_output = trans
    .resolve_attributes()
    .table_name(ddb_table_name)
    .item(item_with_has_test_result.clone())
    .version(1)
    .send()
    .await?;

// Verify that VirtualFields has the expected value
let virtual_fields = resolve_output.virtual_fields.unwrap();
assert_eq!(virtual_fields.len(), 1);
assert_eq!(virtual_fields["stateAndHasTestResult"], "CAt");
```

------

### Menguji suar majemuk
<a name="ddb-beacon-testing-compound-beacon"></a>

Cuplikan berikut membuat item uji, mendefinisikan `DynamoDbEncryptionTransforms` layanan dengan [konfigurasi enkripsi tabel](ddb-java-using.md#ddb-config-encrypt) DynamoDB, dan menunjukkan cara menggunakan untuk memverifikasi bahwa suar majemuk menghasilkan output yang `ResolveAttributes` diharapkan.

------
#### [ Java ]

**Lihat contoh kode lengkapnya**: [CompoundBeaconSearchableEncryptionExample.java](https://github.com/aws/aws-database-encryption-sdk-dynamodb//blob/main/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java) 

```
// Create an item with both attributes used in the compound beacon.
final HashMap<String, AttributeValue> item = new HashMap<>();
item.put("work_id", AttributeValue.builder().s("9ce39272-8068-4efd-a211-cd162ad65d4c").build());
item.put("inspection_date", AttributeValue.builder().s("2023-06-13").build());
item.put("inspector_id_last4", AttributeValue.builder().s("5678").build());
item.put("unit", AttributeValue.builder().s("011899988199").build());
                            
// Define the DynamoDbEncryptionTransforms service
final DynamoDbEncryptionTransforms trans = DynamoDbEncryptionTransforms.builder()
    .DynamoDbTablesEncryptionConfig(encryptionConfig).build();

// Verify configuration 
final ResolveAttributesInput resolveInput = ResolveAttributesInput.builder()
    .TableName(ddbTableName)
    .Item(item)
    .Version(1)
    .build();

final ResolveAttributesOutput resolveOutput = trans.ResolveAttributes(resolveInput);
                            
// Verify that CompoundBeacons has the expected value   
Map<String, String> cbs = new HashMap<>();
cbs.put("last4UnitCompound", "L-5678.U-011899988199");
assert resolveOutput.CompoundBeacons().equals(cbs);
// Note : the compound beacon actually stored in the table is not "L-5678.U-011899988199"
// but rather something like "L-abc.U-123", as both parts are EncryptedParts
// and therefore the text is replaced by the associated beacon
```

------
#### [ C\$1 / .NET ]

**Lihat contoh kode lengkapnya**: [CompoundBeaconSearchableEncryptionExample.cs](https://github.com/aws/aws-database-encryption-sdk-dynamodb/tree/main/Examples/runtimes/net/src/searchableencryption/CompoundBeaconSearchableEncryptionExample.cs)

```
// Create an item with both attributes used in the compound beacon
var item = new Dictionary<String, AttributeValue>
{
    ["work_id"] = new AttributeValue("9ce39272-8068-4efd-a211-cd162ad65d4c"),
    ["inspection_date"] = new AttributeValue("2023-06-13"),
    ["inspector_id_last4"] = new AttributeValue("5678"),
    ["unit"] = new AttributeValue("011899988199")
};                           
                            
// Define the DynamoDbEncryptionTransforms service
var trans = new DynamoDbEncryptionTransforms(encryptionConfig);

// Verify configuration
var resolveInput = new ResolveAttributesInput
{
    TableName = ddbTableName,
    Item = item,
    Version = 1
};
var resolveOutput = trans.ResolveAttributes(resolveInput);                            
                            
// Verify that CompoundBeacons has the expected value 
Debug.Assert(resolveOutput.CompoundBeacons.Count == 1);
Debug.Assert(resolveOutput.CompoundBeacons["last4UnitCompound"] == "L-5678.U-011899988199");
// Note : the compound beacon actually stored in the table is not "L-5678.U-011899988199"
// but rather something like "L-abc.U-123", as both parts are EncryptedParts
// and therefore the text is replaced by the associated beacon
```

------
#### [ Rust ]

**Lihat contoh kode lengkap: [compound\$1beacon\$1searchable\$1encryption.rs](https://github.com/aws/aws-database-encryption-sdk-dynamodb/blob/main/releases/rust/db_esdk/examples/searchableencryption/compound_beacon_searchable_encryption.rs)**

```
// Create an item with both attributes used in the compound beacon
let item = HashMap::from([
    (
        "work_id".to_string(),
        AttributeValue::S("9ce39272-8068-4efd-a211-cd162ad65d4c".to_string()),
    ),
    (
        "inspection_date".to_string(),
        AttributeValue::S("2023-06-13".to_string()),
    ),
    (
        "inspector_id_last4".to_string(),
        AttributeValue::S("5678".to_string()),
    ),
    (
        "unit".to_string(),
        AttributeValue::S("011899988199".to_string()),
    ),
]);                           
                            
// Define the transforms service
let trans = transform_client::Client::from_conf(encryption_config.clone())?;

// Verify configuration
let resolve_output = trans
    .resolve_attributes()
    .table_name(ddb_table_name)
    .item(item.clone())
    .version(1)
    .send()
    .await?;                            
                            
// Verify that CompoundBeacons has the expected value 
let compound_beacons = resolve_output.compound_beacons.unwrap();
assert_eq!(compound_beacons.len(), 1);
assert_eq!(
    compound_beacons["last4UnitCompound"],
    "L-5678.U-011899988199"
);
// but rather something like "L-abc.U-123", as both parts are EncryptedParts
// and therefore the text is replaced by the associated beacon
```

------