• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# oh_rdb_crypto_param.h
2
3## Overview
4
5Defines functions and enums related to encryption parameters of the RDB store.
6
7**File to include**: <database/rdb/oh_rdb_crypto_param.h>
8
9**Library**: libnative_rdb_ndk.z.so
10
11**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
12
13**Since**: 20
14
15**Related module**: [RDB](capi-rdb.md)
16
17## Summary
18
19### Structs
20
21| Name                                            | typedef Keyword     | Description                                |
22| ------------------------------------------------ | ------------------ | ------------------------------------ |
23| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) | OH_Rdb_CryptoParam | Defines the encryption parameters used to open an encrypted database.|
24
25### Enums
26
27| Name                                     | typedef Keyword     | Description                        |
28| ----------------------------------------- | ------------------ | ---------------------------- |
29| [Rdb_EncryptionAlgo](#rdb_encryptionalgo) | Rdb_EncryptionAlgo | Enumerates database encryption algorithms.            |
30| [Rdb_HmacAlgo](#rdb_hmacalgo)             | Rdb_HmacAlgo       | Enumerates HMAC algorithms.|
31| [Rdb_KdfAlgo](#rdb_kdfalgo)               | Rdb_KdfAlgo        | Enumerates KDF algorithms. |
32
33### Functions
34
35| Name                                                        | Description                                                        |
36| ------------------------------------------------------------ | ------------------------------------------------------------ |
37| [OH_Rdb_CryptoParam *OH_Rdb_CreateCryptoParam(void)](#oh_rdb_createcryptoparam) | Creates an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
38| [int OH_Rdb_DestroyCryptoParam(OH_Rdb_CryptoParam *param)](#oh_rdb_destroycryptoparam) | Destroys an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
39| [int OH_Crypto_SetEncryptionKey(OH_Rdb_CryptoParam *param, const uint8_t *key, int32_t length)](#oh_crypto_setencryptionkey) | Sets the key data of an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
40| [int OH_Crypto_SetIteration(OH_Rdb_CryptoParam *param, int64_t iteration)](#oh_crypto_setiteration) | Sets the number of iterations of the KDF algorithm used when opening an encrypted database.                 |
41| [int OH_Crypto_SetEncryptionAlgo(OH_Rdb_CryptoParam *param, int32_t algo)](#oh_crypto_setencryptionalgo) | Sets the encryption algorithm used when opening an encrypted database.                        |
42| [int OH_Crypto_SetHmacAlgo(OH_Rdb_CryptoParam *param, int32_t algo)](#oh_crypto_sethmacalgo) | Sets the HMAC algorithm used when opening an encrypted database.                        |
43| [int OH_Crypto_SetKdfAlgo(OH_Rdb_CryptoParam *param, int32_t algo)](#oh_crypto_setkdfalgo) | Sets the KDF algorithm used when opening an encrypted database.                         |
44| [int OH_Crypto_SetCryptoPageSize(OH_Rdb_CryptoParam *param, int64_t size)](#oh_crypto_setcryptopagesize) | Sets the page size used when opening an encrypted database.                          |
45
46## Enum Description
47
48### Rdb_EncryptionAlgo
49
50```
51enum Rdb_EncryptionAlgo
52```
53
54**Description**
55
56Enumerates database encryption algorithms.
57
58**Since**: 20
59
60| Enum Item             | Description                               |
61| ------------------- | ----------------------------------- |
62| RDB_AES_256_GCM = 0 | RDB_AES_256_GCM.|
63| RDB_AES_256_CBC     | RDB_AES_256_CBC.|
64
65### Rdb_HmacAlgo
66
67```
68enum Rdb_HmacAlgo
69```
70
71**Description**
72
73Enumerates HMAC algorithms.
74
75**Since**: 20
76
77| Enum Item           | Description                 |
78| ----------------- | --------------------- |
79| RDB_HMAC_SHA1 = 0 | RDB_HMAC_SHA1.  |
80| RDB_HMAC_SHA256   | RDB_HMAC_SHA256.|
81| RDB_HMAC_SHA512   | RDB_HMAC_SHA512.|
82
83### Rdb_KdfAlgo
84
85```
86enum Rdb_KdfAlgo
87```
88
89**Description**
90
91Enumerates KDF algorithms.
92
93**Since**: 20
94
95| Enum Item          | Description                |
96| ---------------- | -------------------- |
97| RDB_KDF_SHA1 = 0 | RDB_KDF_SHA1.  |
98| RDB_KDF_SHA256   | RDB_KDF_SHA256.|
99| RDB_KDF_SHA512   | RDB_KDF_SHA512.|
100
101
102## Function Description
103
104### OH_Rdb_CreateCryptoParam()
105
106```
107OH_Rdb_CryptoParam *OH_Rdb_CreateCryptoParam(void)
108```
109
110**Description**
111
112Creates an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.
113
114**Since**: 20
115
116**Returns**
117
118| Type                                                 | Description                                                  |
119| ---------------------------------------------------- | ------------------------------------------------------------ |
120| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) | Returns a pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance if the operation is successful; returns **nullptr** otherwise. Use [OH_Rdb_DestroyCryptoParam](capi-oh-rdb-crypto-param-h.md#oh_rdb_destroycryptoparam) to release the memory in time. |
121
122### OH_Rdb_DestroyCryptoParam()
123
124```
125int OH_Rdb_DestroyCryptoParam(OH_Rdb_CryptoParam *param)
126```
127
128**Description**
129
130Destroys an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.
131
132**Since**: 20
133
134
135**Parameters**
136
137| Name                                                 | Description                                                        |
138| ------------------------------------------------------- | ------------------------------------------------------------ |
139| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
140
141**Returns**
142
143| Type| Description                                                        |
144| ---- | ------------------------------------------------------------ |
145| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
146
147### OH_Crypto_SetEncryptionKey()
148
149```
150int OH_Crypto_SetEncryptionKey(OH_Rdb_CryptoParam *param, const uint8_t *key, int32_t length)
151```
152
153**Description**
154
155Sets the key data of an [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.
156
157**Since**: 20
158
159
160**Parameters**
161
162| Name                                                 | Description                                                        |
163| ------------------------------------------------------- | ------------------------------------------------------------ |
164| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
165| const uint8_t *key                                      | Pointer to the array data.                                    |
166| int32_t length                                          | Size of the key array.                                        |
167
168**Returns**
169
170| Type| Description                                                        |
171| ---- | ------------------------------------------------------------ |
172| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
173
174### OH_Crypto_SetIteration()
175
176```
177int OH_Crypto_SetIteration(OH_Rdb_CryptoParam *param, int64_t iteration)
178```
179
180**Description**
181
182Sets the number of iterations of the KDF algorithm used when opening an encrypted database.
183
184**Since**: 20
185
186
187**Parameters**
188
189| Name                                                 | Description                                                        |
190| ------------------------------------------------------- | ------------------------------------------------------------ |
191| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
192| int64_t iteration                                       | Number of iterations.                                              |
193
194**Returns**
195
196| Type| Description                                                        |
197| ---- | ------------------------------------------------------------ |
198| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
199
200### OH_Crypto_SetEncryptionAlgo()
201
202```
203int OH_Crypto_SetEncryptionAlgo(OH_Rdb_CryptoParam *param, int32_t algo)
204```
205
206**Description**
207
208Sets the encryption algorithm used when opening an encrypted database.
209
210**Since**: 20
211
212
213**Parameters**
214
215| Name                                                 | Description                                                        |
216| ------------------------------------------------------- | ------------------------------------------------------------ |
217| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
218| int32_t algo                                            | Encryption algorithm.                                              |
219
220**Returns**
221
222| Type| Description                                                        |
223| ---- | ------------------------------------------------------------ |
224| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
225
226### OH_Crypto_SetHmacAlgo()
227
228```
229int OH_Crypto_SetHmacAlgo(OH_Rdb_CryptoParam *param, int32_t algo)
230```
231
232**Description**
233
234Sets the HMAC algorithm used when opening an encrypted database.
235
236**Since**: 20
237
238
239**Parameters**
240
241| Name                                                 | Description                                                        |
242| ------------------------------------------------------- | ------------------------------------------------------------ |
243| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
244| int32_t algo                                            | HMAC algorithm.                                              |
245
246**Returns**
247
248| Type| Description                                                        |
249| ---- | ------------------------------------------------------------ |
250| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
251
252### OH_Crypto_SetKdfAlgo()
253
254```
255int OH_Crypto_SetKdfAlgo(OH_Rdb_CryptoParam *param, int32_t algo)
256```
257
258**Description**
259
260Sets the KDF algorithm used when opening an encrypted database.
261
262**Since**: 20
263
264
265**Parameters**
266
267| Name                                                 | Description                                                        |
268| ------------------------------------------------------- | ------------------------------------------------------------ |
269| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
270| int32_t algo                                            | KDF algorithm.                                               |
271
272**Returns**
273
274| Type| Description                                                        |
275| ---- | ------------------------------------------------------------ |
276| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
277
278### OH_Crypto_SetCryptoPageSize()
279
280```
281int OH_Crypto_SetCryptoPageSize(OH_Rdb_CryptoParam *param, int64_t size)
282```
283
284**Description**
285
286Sets the page size used when opening an encrypted database.
287
288**Since**: 20
289
290
291**Parameters**
292
293| Name                                                 | Description                                                        |
294| ------------------------------------------------------- | ------------------------------------------------------------ |
295| [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) *param | Pointer to the [OH_Rdb_CryptoParam](capi-rdb-oh-rdb-cryptoparam.md) instance.|
296| int64_t size                                            | Page size, in bytes. The value must be a power of 2 and ranges from 512 to 65536.|
297
298**Returns**
299
300| Type| Description                                                        |
301| ---- | ------------------------------------------------------------ |
302| int  | Returns an execution result.<br>**RDB_OK** indicates that the execution is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
303