crypto_sym_key.h
Overview
Provides APIs for symmetric keys.
Header file: <CryptoArchitectureKit/crypto_sym_key.h>
Library: libohcrypto.so
System capability: SystemCapability.Security.CryptoFramework
Since: 12
Related module: CryptoSymKeyApi
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_CryptoSymKey | OH_CryptoSymKey | Defines a struct for a symmetric key. |
| OH_CryptoSymKeyGenerator | OH_CryptoSymKeyGenerator | Defines a struct for a symmetric key. |
Functions
Function Description
OH_CryptoSymKeyGenerator_Create()
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Create(const char *algoName, OH_CryptoSymKeyGenerator **ctx)
Description
Creates a symmetric key generator instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoSymKeyGenerator_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *algoName | Pointer the algorithm used to create a generator. For example, AES256, AES128, and SM4. |
| OH_CryptoSymKeyGenerator **ctx | Double pointer to the symmetric key generator 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_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoSymKeyGenerator_Generate()
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Generate(OH_CryptoSymKeyGenerator *ctx, OH_CryptoSymKey **keyCtx)
Description
Randomly generates a symmetric key.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoSymKey_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKeyGenerator *ctx | Pointer to the symmetric key generator instance. |
| OH_CryptoSymKey **keyCtx | Pointer to the symmetric key 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_OPERTION_ERROR: Failed to call an API of a third-party algorithm library. |
OH_CryptoSymKeyGenerator_Convert()
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Convert(OH_CryptoSymKeyGenerator *ctx, const Crypto_DataBlob *keyData, OH_CryptoSymKey **keyCtx)
Description
Converts binary data into a symmetric key.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoSymKey_Destroy.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKeyGenerator *ctx | Pointer to the symmetric key generator instance. |
| const Crypto_DataBlob *keyData | Pointer to the data to convert. |
| OH_CryptoSymKey **keyCtx | Pointer to the symmetric key obtained. |
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_CryptoSymKeyGenerator_GetAlgoName()
const char *OH_CryptoSymKeyGenerator_GetAlgoName(OH_CryptoSymKeyGenerator *ctx)
Description
Obtains the algorithm of a symmetric key generator instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKeyGenerator *ctx | Double pointer to the symmetric key generator instance created. |
Returns
| Type | Description |
|---|---|
| const char * | Algorithm of a symmetric key generator instance. |
OH_CryptoSymKeyGenerator_Destroy()
void OH_CryptoSymKeyGenerator_Destroy(OH_CryptoSymKeyGenerator *ctx)
Description
Destroys a symmetric key generator instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKeyGenerator *ctx | Double pointer to the symmetric key generator instance created. |
OH_CryptoSymKey_GetAlgoName()
const char *OH_CryptoSymKey_GetAlgoName(OH_CryptoSymKey *keyCtx)
Description
Obtains the algorithm of a symmetric key.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKey *keyCtx | Pointer to the symmetric key instance. |
Returns
| Type | Description |
|---|---|
| const char * | Symmetric key algorithm obtained. |
OH_CryptoSymKey_GetKeyData()
OH_Crypto_ErrCode OH_CryptoSymKey_GetKeyData(OH_CryptoSymKey *keyCtx, Crypto_DataBlob *out)
Description
Obtains symmetric key data from a key instance.
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_CryptoSymKey *keyCtx | Pointer to the symmetric key instance. |
| Crypto_DataBlob *out | Pointer to the data obtained. |
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_CryptoSymKey_Destroy()
void OH_CryptoSymKey_Destroy(OH_CryptoSymKey *keyCtx)
Description
Destroys a symmetric key instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_CryptoSymKey *keyCtx | Pointer to the symmetric key 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