harmony 鸿蒙CryptoSymCipherApi

2025-06-12 浏览 (1)

CryptoSymCipherApi

Overview

Provides APIs for symmetric key encryption and decryption.

Since: 12

Summary

Files

NameDescription
crypto_sym_cipher.hDefines APIs for symmetric encryption and decryption.

Types

NameDescription
typedef struct OH_CryptoSymCipher OH_CryptoSymCipherDefines a symmetric encryption and decryption instance.
typedef struct OH_CryptoSymCipherParams OH_CryptoSymCipherParamsDefines symmetric encryption and decryption parameters.

Enums

NameDescription
CryptoSymCipher_ParamsType {
CRYPTO_IV_DATABLOB = 100,
CRYPTO_AAD_DATABLOB = 101,
CRYPTO_TAG_DATABLOB = 102
}
Enumerates the types of symmetric encryption and decryption parameters.

Functions

NameDescription
OH_Crypto_ErrCode OH_CryptoSymCipherParams_Create (OH_CryptoSymCipherParams **params)Creates a symmetric encryption/decryption parameter instance.
OH_Crypto_ErrCode OH_CryptoSymCipherParams_SetParam (OH_CryptoSymCipherParams *params, CryptoSymCipher_ParamsType paramsType, Crypto_DataBlob *value)Sets a symmetric encryption/decryption parameter.
void OH_CryptoSymCipherParams_Destroy (OH_CryptoSymCipherParams *params)Destroys a symmetric encryption/decryption parameter instance.
OH_Crypto_ErrCode OH_CryptoSymCipher_Create (const char *algoName, OH_CryptoSymCipher **ctx)Creates a symmetric cipher instance based on the given algorithm name.
OH_Crypto_ErrCode OH_CryptoSymCipher_Init (OH_CryptoSymCipher *ctx, Crypto_CipherMode mod, OH_CryptoSymKey *key, OH_CryptoSymCipherParams *params)Initializes a symmetric cipher instance.
OH_Crypto_ErrCode OH_CryptoSymCipher_Update (OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out)Updates the data to be encrypted or decrypted.
OH_Crypto_ErrCode OH_CryptoSymCipher_Final (OH_CryptoSymCipher *ctx, Crypto_DataBlob *in, Crypto_DataBlob *out)Outputs the remaining data (generated by the block cipher mode) and finishes the encryption or decryption operation.
const char * OH_CryptoSymCipher_GetAlgoName (OH_CryptoSymCipher *ctx)Obtains the symmetric encryption/decryption algorithm.
void OH_CryptoSymCipher_Destroy (OH_CryptoSymCipher *ctx)Destroys a symmetric cipher instance.

Type Description

OH_CryptoSymCipher

typedef struct OH_CryptoSymCipherOH_CryptoSymCipher

Description

Defines a symmetric encryption and decryption instance.

Since: 12

OH_CryptoSymCipherParams

typedef struct OH_CryptoSymCipherParamsOH_CryptoSymCipherParams

Description

Defines symmetric encryption and decryption parameters.

Since: 12

Enum Description

CryptoSymCipher_ParamsType

enum CryptoSymCipher_ParamsType

Description

Enumerates the types of symmetric encryption and decryption parameters.

Since: 12

EnumDescription
CRYPTO_IV_DATABLOBInitialization vector (IV).
CRYPTO_AAD_DATABLOBAdditional authentication data (AAD).
CRYPTO_TAG_DATABLOBauthTag.

Function Description

OH_CryptoSymCipher_Create()

OH_Crypto_ErrCode OH_CryptoSymCipher_Create (const char *algoName, OH_CryptoSymCipher **ctx )

Description

Creates a symmetric cipher instance based on the given algorithm name.

Since: 12

Parameters

NameDescription
algoNamePointer to the algorithm used to create a symmetric cipher instance. For example, 'AES128|GCM|PKCS7'.
ctxPointer to the symmetric cipher instance created.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: Failed to call an API of a third-party algorithm library.

OH_CryptoSymCipher_Destroy()

void OH_CryptoSymCipher_Destroy (OH_CryptoSymCipher *ctx)

Description

Destroys a symmetric cipher instance.

Since: 12

Parameters

NameDescription
ctxPointer to the symmetric cipher instance to destroy.

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.

Since: 12

Parameters

NameDescription
ctxPointer to the symmetric cipher instance.
inPointer to the data to be encrypted or decrypted.
outPointer to the remaining data encrypted or decrypted.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: Failed to call an API of a third-party algorithm library.

See

OH_CryptoSymCipher_Init

OH_CryptoSymCipher_Update

OH_CryptoSymCipher_GetAlgoName()

const char* OH_CryptoSymCipher_GetAlgoName (OH_CryptoSymCipher *ctx)

Description

Obtains the symmetric encryption/decryption algorithm.

Since: 12

Parameters

NameDescription
ctxPointer to the symmetric cipher instance.

Returns

Symmetric encryption/decryption algorithm obtained.

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 cipher instance.

Since: 12

Parameters

NameDescription
ctxPointer to the symmetric cipher instance.
modOperation to perform, encryption or decryption.
keyPointer to the symmetric key.
paramsPointer to the parameters for encryption or decryption.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: Failed to call an API of a third-party algorithm library.

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.

Since: 12

Parameters

NameDescription
ctxPointer to the symmetric cipher instance.
inData to be encrypted or decrypted.
outPointer to the data updated.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: Failed to call an API of a third-party algorithm library.

OH_CryptoSymCipherParams_Create()

OH_Crypto_ErrCode OH_CryptoSymCipherParams_Create (OH_CryptoSymCipherParams **params)

Description

Creates a symmetric encryption/decryption parameter instance.

Since: 12

Parameters

NameDescription
paramsPointer to the symmetric encryption/decryption parameter instance.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: 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

NameDescription
paramsPointer to the symmetric encryption/decryption parameter instance.

OH_CryptoSymCipherParams_SetParam()

OH_Crypto_ErrCode OH_CryptoSymCipherParams_SetParam (OH_CryptoSymCipherParams *params, CryptoSymCipher_ParamsType paramsType, Crypto_DataBlob *value )

Description

Sets a symmetric encryption/decryption parameter.

Since: 12

Parameters

NameDescription
paramsPointer to the symmetric encryption/decryption parameter instance.
paramsTypeName of the parameter to set.
valuePointer to the parameter value set.

Returns

OH_Crypto_ErrCode:

0: The operation is successful.

401: Invalid parameters are detected.

801: The operation is not supported.

17620001: A memory error occurred.

17630001: Failed to call an API of a third-party algorithm library.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Crypto Architecture Kit (Crypto Architecture Service)

harmony 鸿蒙Crypto_DataBlob

harmony 鸿蒙CryptoAsymKeyApi

harmony 鸿蒙CryptoCommonApi

harmony 鸿蒙CryptoDigestApi

harmony 鸿蒙CryptoSignatureApi

harmony 鸿蒙CryptoSymKeyApi

harmony 鸿蒙crypto_asym_key.h

harmony 鸿蒙crypto_common.h

harmony 鸿蒙crypto_digest.h

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