openharmony 鸿蒙 capi-crypto-sym-key-h

2026-08-25 浏览 (1)

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

Nametypedef KeywordDescription
OH_CryptoSymKeyOH_CryptoSymKeyDefines a struct for a symmetric key.
OH_CryptoSymKeyGeneratorOH_CryptoSymKeyGeneratorDefines a struct for a symmetric key.

Functions

NameDescription
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Create(const char *algoName, OH_CryptoSymKeyGenerator **ctx)Creates a symmetric key generator instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoSymKeyGenerator_Destroy.
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Generate(OH_CryptoSymKeyGenerator *ctx, OH_CryptoSymKey **keyCtx)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.
OH_Crypto_ErrCode OH_CryptoSymKeyGenerator_Convert(OH_CryptoSymKeyGenerator *ctx, const Crypto_DataBlob *keyData, OH_CryptoSymKey **keyCtx)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.
const char *OH_CryptoSymKeyGenerator_GetAlgoName(OH_CryptoSymKeyGenerator *ctx)Obtains the algorithm of a symmetric key generator instance.
void OH_CryptoSymKeyGenerator_Destroy(OH_CryptoSymKeyGenerator *ctx)Destroys a symmetric key generator instance.
const char *OH_CryptoSymKey_GetAlgoName(OH_CryptoSymKey *keyCtx)Obtains the algorithm of a symmetric key.
OH_Crypto_ErrCode OH_CryptoSymKey_GetKeyData(OH_CryptoSymKey *keyCtx, Crypto_DataBlob *out)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.
void OH_CryptoSymKey_Destroy(OH_CryptoSymKey *keyCtx)Destroys a symmetric key instance.

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

NameDescription
const char *algoNamePointer the algorithm used to create a generator.
For example, AES256, AES128, and SM4.
OH_CryptoSymKeyGenerator **ctxDouble pointer to the symmetric key generator instance created.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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

NameDescription
OH_CryptoSymKeyGenerator *ctxPointer to the symmetric key generator instance.
OH_CryptoSymKey **keyCtxPointer to the symmetric key created.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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

NameDescription
OH_CryptoSymKeyGenerator *ctxPointer to the symmetric key generator instance.
const Crypto_DataBlob *keyDataPointer to the data to convert.
OH_CryptoSymKey **keyCtxPointer to the symmetric key obtained.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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

NameDescription
OH_CryptoSymKeyGenerator *ctxDouble pointer to the symmetric key generator instance created.

Returns

TypeDescription
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

NameDescription
OH_CryptoSymKeyGenerator *ctxDouble 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

NameDescription
OH_CryptoSymKey *keyCtxPointer to the symmetric key instance.

Returns

TypeDescription
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

NameDescription
OH_CryptoSymKey *keyCtxPointer to the symmetric key instance.
Crypto_DataBlob *outPointer to the data obtained.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_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

NameDescription
OH_CryptoSymKey *keyCtxPointer 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

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/S3JCfKd3