1# CryptoDigestApi 2 3 4## Overview 5 6Provides APIs for message digest (MD) algorithms. 7 8**Since**: 12 9 10 11## Summary 12 13 14### Files 15 16| Name | Description | 17| -------- | -------- | 18| [crypto_digest.h](crypto__digest_8h.md) | Defines APIs for MD algorithms. | 19 20 21### Types 22 23| Name | Description | 24| -------- | -------- | 25| typedef struct [OH_CryptoDigest](#oh_cryptodigest) [OH_CryptoDigest](#oh_cryptodigest) | Defines an MD. | 26 27 28### Functions 29 30| Name | Description | 31| -------- | -------- | 32| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoDigest_Create](#oh_cryptodigest_create) (const char \*algoName, [OH_CryptoDigest](#oh_cryptodigest) \*\*ctx) | Creates an MD instance based on the given algorithm name. | 33| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoDigest_Update](#oh_cryptodigest_update) ([OH_CryptoDigest](#oh_cryptodigest) \*ctx, [Crypto_DataBlob](_crypto___data_blob.md) \*in) | Updates the data used for generating an MD. | 34| [OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode) [OH_CryptoDigest_Final](#oh_cryptodigest_final) ([OH_CryptoDigest](#oh_cryptodigest) \*ctx, [Crypto_DataBlob](_crypto___data_blob.md) \*out) | Generates an MD. | 35| uint32_t [OH_CryptoDigest_GetLength](#oh_cryptodigest_getlength) ([OH_CryptoDigest](#oh_cryptodigest) \*ctx) | Obtains the length of an MD. | 36| const char \* [OH_CryptoDigest_GetAlgoName](#oh_cryptodigest_getalgoname) ([OH_CryptoDigest](#oh_cryptodigest) \*ctx) | Obtains the digest algorithm. | 37| void [OH_DigestCrypto_Destroy](#oh_digestcrypto_destroy) ([OH_CryptoDigest](#oh_cryptodigest) \*ctx) | Destroys an MD instance. | 38 39 40## Type Description 41 42 43### OH_CryptoDigest 44 45``` 46typedef struct OH_CryptoDigestOH_CryptoDigest 47``` 48 49**Description** 50 51Defines an MD. 52 53**Since**: 12 54 55 56## Function Description 57 58 59### OH_CryptoDigest_Create() 60 61``` 62OH_Crypto_ErrCode OH_CryptoDigest_Create (const char *algoName, OH_CryptoDigest **ctx ) 63``` 64 65**Description** 66 67Creates an MD instance based on the given algorithm name. 68 69**Since**: 12 70 71**Parameters** 72 73| Name | Description | 74| -------- | -------- | 75| algoName | Pointer to the algorithm used to generate the MD instance. For example, **'SHA256'**. | 76| ctx | Pointer to the MD instance created. | 77 78**Returns** 79 80[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 81 82**0**: The operation is successful. 83 84**401**: Invalid parameters are detected. 85 86**801**: The operation is not supported. 87 88**17620001**: A memory error occurred. 89 90**17630001**: Failed to call an API of a third-party algorithm library. 91 92 93### OH_CryptoDigest_Final() 94 95``` 96OH_Crypto_ErrCode OH_CryptoDigest_Final (OH_CryptoDigest *ctx, Crypto_DataBlob *out ) 97``` 98 99**Description** 100 101Generates an MD. 102 103**Since**: 12 104 105**Parameters** 106 107| Name | Description | 108| -------- | -------- | 109| ctx | Pointer to the MD instance. | 110| out | Pointer to the MD generated. | 111 112**Returns** 113 114[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 115 116**0**: The operation is successful. 117 118**401**: Invalid parameters are detected. 119 120**801**: The operation is not supported. 121 122**17620001**: A memory error occurred. 123 124**17630001**: Failed to call an API of a third-party algorithm library. 125 126**See** 127 128[OH_CryptoDigest_Update](#oh_cryptodigest_update) 129 130 131### OH_CryptoDigest_GetAlgoName() 132 133``` 134const char* OH_CryptoDigest_GetAlgoName (OH_CryptoDigest *ctx) 135``` 136 137**Description** 138 139Obtains the digest algorithm. 140 141**Since**: 12 142 143**Parameters** 144 145| Name | Description | 146| -------- | -------- | 147| ctx | Pointer to the MD instance. | 148 149**Returns** 150 151MD algorithm obtained. 152 153 154### OH_CryptoDigest_GetLength() 155 156``` 157uint32_t OH_CryptoDigest_GetLength (OH_CryptoDigest *ctx) 158``` 159 160**Description** 161 162Obtains the length of an MD. 163 164**Since**: 12 165 166**Parameters** 167 168| Name | Description | 169| -------- | -------- | 170| ctx | Pointer to the MD instance. | 171 172**Returns** 173 174[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 175 176**0**: The operation is successful. 177 178**401**: Invalid parameters are detected. 179 180**801**: The operation is not supported. 181 182**17620001**: A memory error occurred. 183 184**17630001**: Failed to call an API of a third-party algorithm library. 185 186 187### OH_CryptoDigest_Update() 188 189``` 190OH_Crypto_ErrCode OH_CryptoDigest_Update (OH_CryptoDigest *ctx, Crypto_DataBlob *in ) 191``` 192 193**Description** 194 195Updates the data used for generating an MD. 196 197**Since**: 12 198 199**Parameters** 200 201| Name | Description | 202| -------- | -------- | 203| ctx | Pointer to the MD instance. | 204| in | Pointer to the data to pass in. | 205 206**Returns** 207 208[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 209 210**0**: The operation is successful. 211 212**401**: Invalid parameters are detected. 213 214**801**: The operation is not supported. 215 216**17620001**: A memory error occurred. 217 218**17630001**: Failed to call an API of a third-party algorithm library. 219 220**See** 221 222[OH_CryptoDigest_Final](#oh_cryptodigest_final) 223 224 225### OH_DigestCrypto_Destroy() 226 227``` 228void OH_DigestCrypto_Destroy (OH_CryptoDigest *ctx) 229``` 230 231**Description** 232 233Destroys an MD instance. 234 235**Since**: 12 236 237**Parameters** 238 239| Name | Description | 240| -------- | -------- | 241| ctx | Pointer to the MD instance. | 242 243**Returns** 244 245[OH_Crypto_ErrCode](_crypto_common_api.md#oh_crypto_errcode): 246 247**0**: The operation is successful. 248 249**401**: Invalid parameters are detected. 250 251**801**: The operation is not supported. 252 253**17620001**: A memory error occurred. 254 255**17630001**: Failed to call an API of a third-party algorithm library. 256