harmony 鸿蒙CryptoAsymKeyApi

2025-06-12 浏览 (1)

CryptoAsymKeyApi

Overview

Provides APIs for asymmetric keys.

Since: 12

Summary

Files

NameDescription
crypto_asym_key.hDefines APIs for asymmetric keys.

Types

NameDescription
typedef struct OH_CryptoKeyPair OH_CryptoKeyPairDefines a struct for an asymmetric key pair.
typedef struct OH_CryptoPubKey OH_CryptoPubKeyDefines a struct for the public key in an asymmetric key pair.
typedef struct OH_CryptoAsymKeyGenerator OH_CryptoAsymKeyGeneratorDefines a struct for an asymmetric key generator.

Enums

NameDescription
CryptoAsymKey_ParamType {
CRYPTO_DSA_P_DATABLOB = 101, CRYPTO_DSA_Q_DATABLOB = 102,
CRYPTO_DSA_G_DATABLOB = 103, CRYPTO_DSA_SK_DATABLOB = 104,
CRYPTO_DSA_PK_DATABLOB = 105, CRYPTO_ECC_FP_P_DATABLOB = 201,
CRYPTO_ECC_A_DATABLOB = 202, CRYPTO_ECC_B_DATABLOB = 203,
CRYPTO_ECC_G_X_DATABLOB = 204, CRYPTO_ECC_G_Y_DATABLOB = 205,
CRYPTO_ECC_N_DATABLOB = 206, CRYPTO_ECC_H_INT = 207,
CRYPTO_ECC_SK_DATABLOB = 208, CRYPTO_ECC_PK_X_DATABLOB = 209,
CRYPTO_ECC_PK_Y_DATABLOB = 210, CRYPTO_ECC_FIELD_TYPE_STR = 211,
CRYPTO_ECC_FIELD_SIZE_INT = 212, CRYPTO_ECC_CURVE_NAME_STR = 213,
CRYPTO_RSA_N_DATABLOB = 301, CRYPTO_RSA_D_DATABLOB = 302,
CRYPTO_RSA_E_DATABLOB = 303, CRYPTO_DH_P_DATABLOB = 401,
CRYPTO_DH_G_DATABLOB = 402, CRYPTO_DH_L_NUM = 403,
CRYPTO_DH_SK_DATABLOB = 404, CRYPTO_DH_PK_DATABLOB = 405,
CRYPTO_ED25519_SK_DATABLOB = 501, CRYPTO_ED25519_PK_DATABLOB = 502,
CRYPTO_X25519_SK_DATABLOB = 601, CRYPTO_X25519_PK_DATABLOB = 602
}
Enumerates the types of the asymmetric key parameters.
Crypto_EncodingType { CRYPTO_PEM = 0, CRYPTO_DER = 1 }Enumerates the encoding types.

Functions

NameDescription
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Create (const char *algoName, OH_CryptoAsymKeyGenerator **ctx)Creates an asymmetric key generator instance based on the specified algorithm.
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Generate (OH_CryptoAsymKeyGenerator *ctx, OH_CryptoKeyPair **keyCtx)Randomly generates an asymmetric key pair.
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Convert (OH_CryptoAsymKeyGenerator *ctx, Crypto_EncodingType type, Crypto_DataBlob *pubKeyData, Crypto_DataBlob *priKeyData, OH_CryptoKeyPair **keyCtx)Converts asymmetric key data into a key pair.
const char * OH_CryptoAsymKeyGenerator_GetAlgoName (OH_CryptoAsymKeyGenerator *ctx)Obtains the asymmetric key algorithm.
void OH_CryptoAsymKeyGenerator_Destroy (OH_CryptoAsymKeyGenerator *ctx)Destroys an asymmetric key generator instance.
void OH_CryptoKeyPair_Destroy (OH_CryptoKeyPair *keyCtx)Destroys an asymmetric key pair instance.
OH_CryptoPubKey * OH_CryptoKeyPair_GetPubKey (OH_CryptoKeyPair *keyCtx)Obtains the public key instance from a key pair.
OH_Crypto_ErrCode OH_CryptoPubKey_Encode (OH_CryptoPubKey *key, Crypto_EncodingType type, const char *encodingStandard, Crypto_DataBlob *out)Encodes the public key data in the specified format.
OH_Crypto_ErrCode OH_CryptoPubKey_GetParam (OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value)Obtains the specified parameter from a public key instance.

Type Description

OH_CryptoAsymKeyGenerator

typedef struct OH_CryptoAsymKeyGenerator OH_CryptoAsymKeyGenerator

Description

Defines a struct for an asymmetric key generator.

Since: 12

OH_CryptoKeyPair

typedef struct OH_CryptoKeyPair OH_CryptoKeyPair

Description

Defines a struct for an asymmetric key pair.

Since: 12

OH_CryptoPubKey

typedef struct OH_CryptoPubKey OH_CryptoPubKey

Description

Defines a struct for the public key in an asymmetric key pair.

Since: 12

Enum Description

Crypto_EncodingType

enum Crypto_EncodingType

Description

Enumerates the encoding types.

Since: 12

EnumDescription
CRYPTO_PEMPEM.
CRYPTO_DERDER.

CryptoAsymKey_ParamType

enum CryptoAsymKey_ParamType

Description

Enumerates the types of the asymmetric key parameters.

Since: 12

EnumDescription
CRYPTO_DSA_P_DATABLOBPrime modulus p in the DSA algorithm.
CRYPTO_DSA_Q_DATABLOBParameter q, prime factor of (p – 1) in the DSA algorithm.
CRYPTO_DSA_G_DATABLOBParameter g in the DSA algorithm.
CRYPTO_DSA_SK_DATABLOBPrivate key sk in the DSA algorithm.
CRYPTO_DSA_PK_DATABLOBPublic key pk in the DSA algorithm.
CRYPTO_ECC_FP_P_DATABLOBPrime number p in the Fp field of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_A_DATABLOBFirst coefficient a of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_B_DATABLOBSecond coefficient b of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_G_X_DATABLOBX coordinate of the base point g in the ECC algorithm.
CRYPTO_ECC_G_Y_DATABLOBY coordinate of the base point g in the ECC algorithm.
CRYPTO_ECC_N_DATABLOBOrder n of the base point g in the ECC algorithm.
CRYPTO_ECC_H_INTCofactor h in the ECC algorithm.
CRYPTO_ECC_SK_DATABLOBPrivate key sk in the ECC algorithm.
CRYPTO_ECC_PK_X_DATABLOBX coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm.
CRYPTO_ECC_PK_Y_DATABLOBY coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm.
CRYPTO_ECC_FIELD_TYPE_STRElliptic curve field type in the ECC algorithm. Currently, only the Fp field is supported.
CRYPTO_ECC_FIELD_SIZE_INTSize of the field in the ECC algorithm, in bits.
NOTE: The size of the Fp field is the length of the prime p, in bits.
CRYPTO_ECC_CURVE_NAME_STRStandards for Efficient Cryptography Group (SECG) curve name in the ECC algorithm.
CRYPTO_RSA_N_DATABLOBModulus n in the RSA algorithm.
CRYPTO_RSA_D_DATABLOBPrivate key sk (private key exponent d) in the RSA algorithm.
CRYPTO_RSA_E_DATABLOBPublic key pk (public key exponent e) in the RSA algorithm.
CRYPTO_DH_P_DATABLOBPrime p in the DH algorithm.
CRYPTO_DH_G_DATABLOBParameter g in the DH algorithm.
CRYPTO_DH_L_NUMLength of the private key in the DH algorithm, in bits.
CRYPTO_DH_SK_DATABLOBPrivate key sk in the DH algorithm.
CRYPTO_DH_PK_DATABLOBPublic key pk in the DH algorithm.
CRYPTO_ED25519_SK_DATABLOBPrivate key sk in the Ed25519 algorithm.
CRYPTO_ED25519_PK_DATABLOBPublic key pk in the Ed25519 algorithm.
CRYPTO_X25519_SK_DATABLOBPrivate key sk in the X25519 algorithm.
CRYPTO_X25519_PK_DATABLOBPublic key pk in the X25519 algorithm.

Function Description

OH_CryptoAsymKeyGenerator_Convert()

OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Convert (OH_CryptoAsymKeyGenerator *ctx, Crypto_EncodingType type, Crypto_DataBlob *pubKeyData, Crypto_DataBlob *priKeyData, OH_CryptoKeyPair **keyCtx )

Description

Converts binary data into an asymmetric key pair.

Since: 12

Parameters

NameDescription
ctxPointer to the asymmetric key generator instance.
typeEncoding type.
pubKeyDataPointer to the public key data to convert.
priKeyDataPointer to the private key data to convert.
keyCtxPointer to the asymmetric key pair 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_CryptoAsymKeyGenerator_Create()

OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Create (const char *algoName, OH_CryptoAsymKeyGenerator **ctx )

Description

Creates an asymmetric key generator instance based on the specified algorithm.

Since: 12

Parameters

NameDescription
algoNamePointer to the algorithm used to create the asymmetric key generator instance. For example, 'RSA1024|PRIMES_2'.
ctxPointer to the asymmetric key generator 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_CryptoAsymKeyGenerator_Destroy()

void OH_CryptoAsymKeyGenerator_Destroy (OH_CryptoAsymKeyGenerator *ctx)

Description

Destroys an asymmetric key generator instance.

Since: 12

Parameters

NameDescription
ctxPointer to the asymmetric key generator instance to destroy.

OH_CryptoAsymKeyGenerator_Generate()

OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Generate (OH_CryptoAsymKeyGenerator *ctx, OH_CryptoKeyPair **keyCtx )

Description

Randomly generates an asymmetric key pair.

Since: 12

Parameters

NameDescription
ctxPointer to the asymmetric key generator instance.
keyCtxPointer to the asymmetric key pair 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_CryptoAsymKeyGenerator_GetAlgoName()

const char* OH_CryptoAsymKeyGenerator_GetAlgoName (OH_CryptoAsymKeyGenerator *ctx)

Description

Obtains the asymmetric key algorithm.

Since: 12

Parameters

NameDescription
ctxPointer to the asymmetric key generator instance.

Returns

Name of the asymmetric key algorithm obtained.

OH_CryptoKeyPair_Destroy()

void OH_CryptoKeyPair_Destroy (OH_CryptoKeyPair *keyCtx)

Description

Destroys an asymmetric key pair instance.

Since: 12

Parameters

NameDescription
keyCtxPointer to the asymmetric key pair instance to destroy.

OH_CryptoKeyPair_GetPubKey()

OH_CryptoPubKey* OH_CryptoKeyPair_GetPubKey (OH_CryptoKeyPair *keyCtx)

Description

Obtains the public key from a key pair.

Since: 12

Parameters

NameDescription
keyCtxPointer to the key pair instance.

Returns

Public key obtained.

OH_CryptoPubKey_Encode()

OH_Crypto_ErrCode OH_CryptoPubKey_Encode (OH_CryptoPubKey *key, Crypto_EncodingType type, const char *encodingStandard, Crypto_DataBlob *out )

Description

Encodes the public key data in the specified format.

Since: 12

Parameters

NameDescription
keyPonter to the public key data.
typeEncoding type.
encodingStandardEncoding format.
outPointer to the public key encoded in the specified format.

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_CryptoPubKey_GetParam()

OH_Crypto_ErrCode OH_CryptoPubKey_GetParam (OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value )

Description

Obtains the specified parameter from a public key instance.

Since: 12

Parameters

NameDescription
keyPonter to the public key data.
itemType of the asymmetric key parameter to obtain.
valuePointer to the parameter value obtained.

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 鸿蒙CryptoCommonApi

harmony 鸿蒙CryptoDigestApi

harmony 鸿蒙CryptoSignatureApi

harmony 鸿蒙CryptoSymCipherApi

harmony 鸿蒙CryptoSymKeyApi

harmony 鸿蒙crypto_asym_key.h

harmony 鸿蒙crypto_common.h

harmony 鸿蒙crypto_digest.h

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