crypto_sym_cipher.h
Overview
Defines APIs for encrypting and decrypting symmetric keys.
Header file: <CryptoArchitectureKit/crypto_sym_cipher.h>
Library: libohcrypto.so
System capability: SystemCapability.Security.CryptoFramework
Since: 12
Related module: CryptoSymCipherApi
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_CryptoSymCipher | OH_CryptoSymCipher | Defines a symmetric encryption and decryption instance. |
| OH_CryptoSymCipherParams | OH_CryptoSymCipherParams | Defines symmetric encryption and decryption parameters. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| CryptoSymCipher_ParamsType | CryptoSymCipher_ParamsType | Enumerates the types of symmetric encryption and decryption parameters. |
Functions
Enum Description
CryptoSymCipher_ParamsType
enum CryptoSymCipher_ParamsType
Description
Enumerates the types of symmetric encryption and decryption parameters.
Since: 12
| Enum Item | Description |
|---|---|
| CRYPTO_IV_DATABLOB = 100 | Parameters such as iv. |
| CRYPTO_AAD_DATABLOB = 101 | Additional authentication data in GCM mode. |
| CRYPTO_TAG_DATABLOB = 102 | Output tag of the encryption operation, which is used for integrity check. |
Function Description
OH_CryptoSymCipherParams_Create()
OH_Crypto_ErrCode OH_CryptoSymCipherParams_Create(OH_CryptoSymCipherParams **params)
Description
Creates a symmetric encryption/decryption parameter instance.
Note: The created resource must be destroyed by calling OH_CryptoSymCipherParams_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipherParams **params | Pointer to the symmetric encryption/decryption parameter instance. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoSymCipherParams_SetParam()
OH_Crypto_ErrCode OH_CryptoSymCipherParams_SetParam(OH_CryptoSymCipherParams *params, CryptoSymCipher_ParamsType paramsType, Crypto_DataBlob *value)
Description
Sets symmetric encryption/decryption parameters.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipherParams *params | Pointer to the symmetric encryption/decryption parameter instance. |
| CryptoSymCipher_ParamsType paramsType | Name of the parameter to set. |
| Crypto_DataBlob *value | Pointer to the parameter value set. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoSymCipherParams_Destroy()
void OH_CryptoSymCipherParams_Destroy(OH_CryptoSymCipherParams *params)
Description
Destroys a symmetric encryption/decryption parameter instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipherParams *params | Pointer to the symmetric encryption/decryption parameter instance. |
OH_CryptoSymCipher_Create()
OH_Crypto_ErrCode OH_CryptoSymCipher_Create(const char *algoName, OH_CryptoSymCipher **ctx)
Description
Creates a symmetric encryption/decryption instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoSymCipher_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *algoName | Pointer to the algorithm used to generate a cipher instance. For example, AES128|GCM|PKCS7. |
| OH_CryptoSymCipher **ctx | Pointer to the symmetric cipher instance created. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: Parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoSymCipher_Init()
OH_Crypto_ErrCode OH_CryptoSymCipher_Init(OH_CryptoSymCipher *ctx, Crypto_CipherMode mod, OH_CryptoSymKey *key, OH_CryptoSymCipherParams *params)
Description
Initializes a symmetric encryption/decryption instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipher *ctx | Pointer to the symmetric key cipher instance. |
| Crypto_CipherMode mod | Operation to perform, encryption or decryption. |
| OH_CryptoSymKey *key | Pointer to the symmetric key. |
| OH_CryptoSymCipherParams *params | Pointer to the parameters for encryption or decryption. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: Parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
Reference
OH_CryptoSymCipher_Update()
OH_Crypto_ErrCode OH_CryptoSymCipher_Update(OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out)
Description
Updates the data to be encrypted or decrypted.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipher *ctx | Pointer to the symmetric cipher instance. |
| Crypto_DataBlob *in | Pointer to the data to be encrypted or decrypted. |
| Crypto_DataBlob *out | Pointer to the data updated. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: Parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
Reference
OH_CryptoSymCipher_Final()
OH_Crypto_ErrCode OH_CryptoSymCipher_Final(OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out)
Description
Outputs the remaining data (generated by the block cipher mode) and finishes the encryption or decryption operation.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipher *ctx | Pointer to the symmetric key cipher instance. |
| Crypto_DataBlob *in | Pointer to the data to be encrypted or decrypted. |
| Crypto_DataBlob *out | Pointer to the remaining data encrypted or decrypted. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_SUCCESS: The operation is successful. CRYPTO_INVALID_PARAMS: A parameter is invalid. CRYPTO_NOT_SUPPORTED: The operation is not supported. CRYPTO_MEMORY_ERROR: A memory error occurs. CRYPTO_PARAMETER_CHECK_FAILED: Parameter check failed. CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
Reference
OH_CryptoSymCipher_GetAlgoName()
const char *OH_CryptoSymCipher_GetAlgoName(OH_CryptoSymCipher *ctx)
Description
Obtains the symmetric encryption/decryption algorithm.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipher *ctx | Pointer to the symmetric cipher instance. |
Returns
| Type | Description |
|---|---|
| const char * | Symmetric key encryption algorithm obtained. |
OH_CryptoSymCipher_Destroy()
void OH_CryptoSymCipher_Destroy(OH_CryptoSymCipher *ctx)
Description
Destroys a symmetric encryption/decryption instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymCipher *ctx | Pointer to the symmetric cipher instance. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 capi-cryptosymkeyapi-oh-cryptosymkey
openharmony 鸿蒙 capi-cryptoasymkeyapi-oh-cryptoasymkeygeneratorwithspec
openharmony 鸿蒙 capi-cryptoasymcipherapi-oh-cryptoasymcipher
openharmony 鸿蒙 capi-cryptokdfapi-oh-cryptokdfparams
openharmony 鸿蒙 capi-cryptomacapi
openharmony 鸿蒙 capi-cryptodigestapi-oh-cryptodigest
openharmony 鸿蒙 capi-cryptomacapi-oh-cryptomac
openharmony 鸿蒙 capi-cryptosignatureapi-oh-cryptoeccsignaturespec
openharmony 鸿蒙 capi-cryptocommonapi-crypto-datablob
openharmony 鸿蒙 capi-cryptoasymcipherapi-oh-cryptosm2ciphertextspec