openharmony 鸿蒙 capi-crypto-asym-cipher-h

2026-08-25 浏览 (1)

crypto_asym_cipher.h

Overview

Defines APIs for encrypting and decrypting asymmetric keys.

Header file: <CryptoArchitectureKit/crypto_asym_cipher.h>

Library: libohcrypto.so

System capability: SystemCapability.Security.CryptoFramework

Since: 20

Related module: CryptoAsymCipherApi

Summary

Structs

Nametypedef KeywordDescription
OH_CryptoAsymCipherOH_CryptoAsymCipherDefines asymmetric encryption.
OH_CryptoSm2CiphertextSpecOH_CryptoSm2CiphertextSpecDefines SM2 ciphertext specifications.

Enums

Nametypedef KeywordDescription
CryptoSm2CiphertextSpec_itemCryptoSm2CiphertextSpec_itemDefines the type of SM2 ciphertext specification items.

Functions

NameDescription
OH_Crypto_ErrCode OH_CryptoAsymCipher_Create(const char *algoName, OH_CryptoAsymCipher **ctx)Creates an asymmetric encryption instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoAsymCipher_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymCipher_Init(OH_CryptoAsymCipher *ctx, Crypto_CipherMode mode, OH_CryptoKeyPair *key)Initializes asymmetric encryption.
OH_Crypto_ErrCode OH_CryptoAsymCipher_Final(OH_CryptoAsymCipher *ctx, const Crypto_DataBlob *in, Crypto_DataBlob *out)Finalizes asymmetric encryption.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
void OH_CryptoAsymCipher_Destroy(OH_CryptoAsymCipher *ctx)Destroys an asymmetric encryption context.
OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Create(Crypto_DataBlob *sm2Ciphertext, OH_CryptoSm2CiphertextSpec **spec)Creates SM2 ciphertext specifications.
Note: The created resource must be destroyed by calling OH_CryptoSm2CiphertextSpec_Destroy.
OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_GetItem(OH_CryptoSm2CiphertextSpec *spec, CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *out)Obtains a specified item in SM2 ciphertext specifications.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_SetItem(OH_CryptoSm2CiphertextSpec *spec, CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *in)Sets a specified item in SM2 ciphertext specifications.
OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Encode(OH_CryptoSm2CiphertextSpec *spec, Crypto_DataBlob *out)Encodes SM2 ciphertext specifications into DER ciphertext.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
void OH_CryptoSm2CiphertextSpec_Destroy(OH_CryptoSm2CiphertextSpec *spec)Destroys SM2 ciphertext specifications.

Enum Description

CryptoSm2CiphertextSpec_item

enum CryptoSm2CiphertextSpec_item

Description

Defines the type of SM2 ciphertext specification items.

Since: 20

Enum ItemDescription
CRYPTO_SM2_CIPHERTEXT_C1_X = 0Public key x, also called C1x.
CRYPTO_SM2_CIPHERTEXT_C1_Y = 1Public key y, also called C1y.
CRYPTO_SM2_CIPHERTEXT_C2 = 2Hash value, also called C2.
CRYPTO_SM2_CIPHERTEXT_C3 = 3Ciphertext data, also called C3.

Function Description

OH_CryptoAsymCipher_Create()

OH_Crypto_ErrCode OH_CryptoAsymCipher_Create(const char *algoName, OH_CryptoAsymCipher **ctx)

Description

Creates an asymmetric encryption instance based on the given algorithm name.
Note: The created resource must be destroyed by calling OH_CryptoAsymCipher_Destroy.

Since: 20

Parameters

NameDescription
const char *algoNamePointer to the algorithm used to generate an encryption instance.
For example, RSA|PKCS1_OAEP|SHA384|MGF1_SHA384 or SM2|SM3.
OH_CryptoAsymCipher **ctxPointer to the asymmetric encryption context.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoAsymCipher_Init()

OH_Crypto_ErrCode OH_CryptoAsymCipher_Init(OH_CryptoAsymCipher *ctx, Crypto_CipherMode mode, OH_CryptoKeyPair *key)

Description

Initializes asymmetric encryption.

Since: 20

Parameters

NameDescription
OH_CryptoAsymCipher *ctxPointer to the asymmetric encryption context.
Crypto_CipherMode modeCipher mode (encryption or decryption).
OH_CryptoKeyPair *keyPointer to the asymmetric key.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

Reference

OH_CryptoAsymCipher_Final

OH_CryptoAsymCipher_Final()

OH_Crypto_ErrCode OH_CryptoAsymCipher_Final(OH_CryptoAsymCipher *ctx, const Crypto_DataBlob *in, Crypto_DataBlob *out)

Description

Finalizes asymmetric encryption.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoAsymCipher *ctxPointer to the asymmetric encryption context.
const Crypto_DataBlob *inPointer to the data to be encrypted or decrypted.
Crypto_DataBlob *outPointer to the encrypted or decrypted data.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

Reference

OH_CryptoAsymCipher_Init

OH_CryptoAsymCipher_Destroy()

void OH_CryptoAsymCipher_Destroy(OH_CryptoAsymCipher *ctx)

Description

Destroys an asymmetric encryption context.

Parameters

NameDescription
OH_CryptoAsymCipher *ctxPointer to the asymmetric encryption context.

OH_CryptoSm2CiphertextSpec_Create()

OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Create(Crypto_DataBlob *sm2Ciphertext, OH_CryptoSm2CiphertextSpec **spec)

Description

Creates SM2 ciphertext specifications.
Note: The created resource must be destroyed by calling OH_CryptoSm2CiphertextSpec_Destroy.

Since: 20

Parameters

NameDescription
Crypto_DataBlob *sm2CiphertextPointer to the SM2 ciphertext in DER format. If the value is NULL, an empty SM2 ciphertext specification is created.
OH_CryptoSm2CiphertextSpec **specPointer to the output SM2 ciphertext specifications.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoSm2CiphertextSpec_GetItem()

OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_GetItem(OH_CryptoSm2CiphertextSpec *spec, CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *out)

Description

Obtains a specified item in SM2 ciphertext specifications.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoSm2CiphertextSpec *specPointer to the SM2 ciphertext specifications.
CryptoSm2CiphertextSpec_item itemPointer to the SM2 ciphertext specifications.
Crypto_DataBlob *outPointer to the output data.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoSm2CiphertextSpec_SetItem()

OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_SetItem(OH_CryptoSm2CiphertextSpec *spec, CryptoSm2CiphertextSpec_item item, Crypto_DataBlob *in)

Description

Sets a specified item in SM2 ciphertext specifications.

Since: 20

Parameters

NameDescription
OH_CryptoSm2CiphertextSpec *specPointer to the SM2 ciphertext specifications.
CryptoSm2CiphertextSpec_item itemPointer to the SM2 ciphertext specifications.
Crypto_DataBlob *inPointer to the input data.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoSm2CiphertextSpec_Encode()

OH_Crypto_ErrCode OH_CryptoSm2CiphertextSpec_Encode(OH_CryptoSm2CiphertextSpec *spec, Crypto_DataBlob *out)

Description

Encodes SM2 ciphertext specifications into DER ciphertext.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoSm2CiphertextSpec *specPointer to the SM2 ciphertext specifications.
Crypto_DataBlob *outPointer to the output data.

Returns

TypeDescription
OH_Crypto_ErrCodeCRYPTO_SUCCESS: The operation is successful.
CRYPTO_NOT_SUPPORTED: The operation is not supported.
CRYPTO_MEMORY_ERROR: A memory error occurs.
CRYPTO_PARAMETER_CHECK_FAILED: The parameter check failed.
CRYPTO_OPERTION_ERROR: Failed to call an API of a third-party algorithm library.

OH_CryptoSm2CiphertextSpec_Destroy()

void OH_CryptoSm2CiphertextSpec_Destroy(OH_CryptoSm2CiphertextSpec *spec)

Description

Destroys SM2 ciphertext specifications.

Since: 20

Parameters

NameDescription
OH_CryptoSm2CiphertextSpec *specPointer to the SM2 ciphertext specifications.

你可能感兴趣的鸿蒙文章

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/il5mydyd