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

2026-08-25 浏览 (1)

crypto_asym_key.h

Overview

Defines APIs for asymmetric keys.

Header file: <CryptoArchitectureKit/crypto_asym_key.h>

Library: libohcrypto.so

System capability: SystemCapability.Security.CryptoFramework

Since: 12

Related module: CryptoAsymKeyApi

Summary

Structs

Nametypedef KeywordDescription
OH_CryptoKeyPairOH_CryptoKeyPairDefines a struct for an asymmetric key pair.
OH_CryptoPubKeyOH_CryptoPubKeyDefines a struct for the public key in an asymmetric key pair.
OH_CryptoPrivKeyOH_CryptoPrivKeyDefines a struct for a private key.
OH_CryptoAsymKeyGeneratorOH_CryptoAsymKeyGeneratorDefines a struct for an asymmetric key generator.
OH_CryptoPrivKeyEncodingParamsOH_CryptoPrivKeyEncodingParamsDefines a struct for private key encoding parameters.
OH_CryptoAsymKeySpecOH_CryptoAsymKeySpecDefines a struct for asymmetric key specifications.
OH_CryptoAsymKeyGeneratorWithSpecOH_CryptoAsymKeyGeneratorWithSpecDefines a struct for an asymmetric key generator with specifications.
OH_CryptoEcPointOH_CryptoEcPointDefines a struct for an EC point.

Enums

Nametypedef KeywordDescription
CryptoAsymKey_ParamTypeCryptoAsymKey_ParamTypeEnumerates the types of the asymmetric key parameters.
Crypto_EncodingTypeCrypto_EncodingTypeEnumerates the encoding types.
CryptoPrivKeyEncoding_ParamTypeCryptoPrivKeyEncoding_ParamTypeDefines the parameter type for private key encoding.
CryptoAsymKeySpec_TypeCryptoAsymKeySpec_TypeDefines the specification type of an asymmetric key.

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.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeyGenerator_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_Generate(OH_CryptoAsymKeyGenerator *ctx, OH_CryptoKeyPair **keyCtx)Randomly generates an asymmetric key pair.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoKeyPair_Destroy.
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.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoKeyPair_Destroy.
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_CryptoPrivKey *OH_CryptoKeyPair_GetPrivKey(OH_CryptoKeyPair *keyCtx)Obtains the private key of 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.
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_CryptoPubKey_GetParam(OH_CryptoPubKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value)Obtains the specified parameter from a public key instance.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.
OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_SetPassword(OH_CryptoAsymKeyGenerator *ctx, const unsigned char *password, uint32_t passwordLen)Sets the password of the asymmetric key generator context.
OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_Create(OH_CryptoPrivKeyEncodingParams **ctx)Creates private key encoding parameters.
Note: The created resource must be destroyed by calling OH_CryptoPrivKeyEncodingParams_Destroy.
OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_SetParam(OH_CryptoPrivKeyEncodingParams *ctx, CryptoPrivKeyEncoding_ParamType type, Crypto_DataBlob *value)Sets a private key encoding parameter.
void OH_CryptoPrivKeyEncodingParams_Destroy(OH_CryptoPrivKeyEncodingParams *ctx)Destroys a private key encoding parameter.
OH_Crypto_ErrCode OH_CryptoPrivKey_Encode(OH_CryptoPrivKey *key, Crypto_EncodingType type, const char *encodingStandard, OH_CryptoPrivKeyEncodingParams *params, Crypto_DataBlob *out)Obtains the specified parameter from a private key instance.
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_CryptoPrivKey_GetParam(OH_CryptoPrivKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value)Obtains the specified parameter of a private key.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenEcCommonParamsSpec(const char *curveName, OH_CryptoAsymKeySpec **spec)Generates EC common parameter specifications.
Note: After the use is complete, the memory for storing the spec parameter must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenDhCommonParamsSpec(int pLen, int skLen, OH_CryptoAsymKeySpec **spec)Generates DH common parameter specifications.
Note: After the use is complete, the memory for storing the spec parameter must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_Create(const char *algoName, CryptoAsymKeySpec_Type type, OH_CryptoAsymKeySpec **spec)Creates asymmetric key specifications based on the given algorithm name and specification type.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, Crypto_DataBlob *value)Sets the specified parameters for asymmetric key specifications.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetCommonParamsSpec(OH_CryptoAsymKeySpec *spec, OH_CryptoAsymKeySpec *commonParamsSpec)Sets the common parameter specifications for asymmetric key specifications.
OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, Crypto_DataBlob *value)Obtains the specified parameters for asymmetric key specifications.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.
void OH_CryptoAsymKeySpec_Destroy(OH_CryptoAsymKeySpec *spec)Destroys asymmetric key specifications.
OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_Create(OH_CryptoAsymKeySpec *keySpec, OH_CryptoAsymKeyGeneratorWithSpec **generator)Creates a struct for an asymmetric key generator with specifications.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeyGeneratorWithSpec_Destroy.
OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_GenKeyPair(OH_CryptoAsymKeyGeneratorWithSpec *generator, OH_CryptoKeyPair **keyPair)Generates a key pair based on asymmetric key specifications.
Note: After the use is complete, the memory for storing the keyPair parameter must be released by calling OH_CryptoKeyPair_Destroy.
void OH_CryptoAsymKeyGeneratorWithSpec_Destroy(OH_CryptoAsymKeyGeneratorWithSpec *generator)Destroys a struct for an asymmetric key generator with specifications.
OH_Crypto_ErrCode OH_CryptoEcPoint_Create(const char *curveName, Crypto_DataBlob *ecKeyData, OH_CryptoEcPoint **point)Creates an EC point.
Note: The created resource must be destroyed by calling OH_CryptoEcPoint_Destroy.
OH_Crypto_ErrCode OH_CryptoEcPoint_GetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y)Obtains the X and Y coordinates of an EC point.
Note: After the use is complete, the memory for storing the x and y parameters must be released by calling OH_Crypto_FreeDataBlob.
OH_Crypto_ErrCode OH_CryptoEcPoint_SetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y)Sets the X and Y coordinates of an EC point.
OH_Crypto_ErrCode OH_CryptoEcPoint_Encode(OH_CryptoEcPoint *point, const char *format, Crypto_DataBlob *out)Encodes an EC point in a specified format.
Note: After the use is complete, the memory for storing the out parameter must be released by calling OH_Crypto_FreeDataBlob.
void OH_CryptoEcPoint_Destroy(OH_CryptoEcPoint *point)Destroys an EC point.

Enum Description

CryptoAsymKey_ParamType

enum CryptoAsymKey_ParamType

Description

Enumerates the types of the asymmetric key parameters.

Since: 12

Enum ItemDescription
CRYPTO_DSA_P_DATABLOB = 101Prime modulus p in the DSA algorithm.
CRYPTO_DSA_Q_DATABLOB = 102Parameter q, prime factor of (p – 1) in the DSA algorithm.
CRYPTO_DSA_G_DATABLOB = 103Parameter g in the DSA algorithm.
CRYPTO_DSA_SK_DATABLOB = 104Private key sk in the DSA algorithm.
CRYPTO_DSA_PK_DATABLOB = 105Public key pk in the DSA algorithm.
CRYPTO_ECC_FP_P_DATABLOB = 201Prime number p in the Fp field of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_A_DATABLOB = 202First coefficient a of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_B_DATABLOB = 203Second coefficient b of the elliptic curve in the ECC algorithm.
CRYPTO_ECC_G_X_DATABLOB = 204X coordinate of the base point g in the ECC algorithm.
CRYPTO_ECC_G_Y_DATABLOB = 205Y coordinate of the base point g in the ECC algorithm.
CRYPTO_ECC_N_DATABLOB = 206Order n of the base point g in the ECC algorithm.
CRYPTO_ECC_H_INT = 207Cofactor h in the ECC algorithm.
CRYPTO_ECC_SK_DATABLOB = 208Private key sk in the ECC algorithm.
CRYPTO_ECC_PK_X_DATABLOB = 209X coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm.
CRYPTO_ECC_PK_Y_DATABLOB = 210Y coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm.
CRYPTO_ECC_FIELD_TYPE_STR = 211Elliptic curve field type in the ECC algorithm. Currently, only the Fp field is supported.
CRYPTO_ECC_FIELD_SIZE_INT = 212Size 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_STR = 213Standards for Efficient Cryptography Group (SECG) curve name in the ECC algorithm.
CRYPTO_RSA_N_DATABLOB = 301Modulus n in the RSA algorithm.
CRYPTO_RSA_D_DATABLOB = 302Private key sk (private key exponent d) in the RSA algorithm.
CRYPTO_RSA_E_DATABLOB = 303Public key pk (public key exponent e) in the RSA algorithm.
CRYPTO_DH_P_DATABLOB = 401Prime p in the DH algorithm.
CRYPTO_DH_G_DATABLOB = 402Parameter g in the DH algorithm.
CRYPTO_DH_L_INT = 403Length of the private key in the DH algorithm, in bits.
CRYPTO_DH_SK_DATABLOB = 404Private key sk in the DH algorithm.
CRYPTO_DH_PK_DATABLOB = 405Public key pk in the DH algorithm.
CRYPTO_ED25519_SK_DATABLOB = 501Private key sk in the Ed25519 algorithm.
CRYPTO_ED25519_PK_DATABLOB = 502Public key pk in the Ed25519 algorithm.
CRYPTO_X25519_SK_DATABLOB = 601Private key sk in the X25519 algorithm.
CRYPTO_X25519_PK_DATABLOB = 602Public key pk in the X25519 algorithm.

Crypto_EncodingType

enum Crypto_EncodingType

Description

Enumerates the encoding types.

Since: 12

Enum ItemDescription
CRYPTO_PEM = 0PEM.
CRYPTO_DER = 1DER.

CryptoPrivKeyEncoding_ParamType

enum CryptoPrivKeyEncoding_ParamType

Description

Defines the parameter type for private key encoding.

Since: 20

Enum ItemDescription
CRYPTO_PRIVATE_KEY_ENCODING_PASSWORD_STR = 0Password string.
CRYPTO_PRIVATE_KEY_ENCODING_SYMMETRIC_CIPHER_STR = 1Symmetric cipher string.

CryptoAsymKeySpec_Type

enum CryptoAsymKeySpec_Type

Description

Defines the specification type of an asymmetric key.

Since: 20

Enum ItemDescription
CRYPTO_ASYM_KEY_COMMON_PARAMS_SPEC = 0Common parameter specifications.
CRYPTO_ASYM_KEY_PRIVATE_KEY_SPEC = 1Private key specifications.
CRYPTO_ASYM_KEY_PUBLIC_KEY_SPEC = 2Public key specifications.
CRYPTO_ASYM_KEY_KEY_PAIR_SPEC = 3Key pair specifications.

Function Description

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.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeyGenerator_Destroy.

Since: 12

Parameters

NameDescription
const char *algoNamePointer the algorithm used to create a generator.
For example, RSA1024|PRIMES_2.
OH_CryptoAsymKeyGenerator **ctxPointer to the asymmetric key generator context 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_CryptoAsymKeyGenerator_Generate()

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

Description

Randomly generates an asymmetric key pair.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoKeyPair_Destroy.

Since: 12

Parameters

NameDescription
OH_CryptoAsymKeyGenerator *ctxPointer to the asymmetric key generator instance.
OH_CryptoKeyPair **keyCtxPointer to the asymmetric key pair instance.

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_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 asymmetric key data into a key pair.
Note: After the use is complete, the memory for storing the keyCtx parameter must be destroyed by calling OH_CryptoKeyPair_Destroy.

Since: 12

Parameters

NameDescription
OH_CryptoAsymKeyGenerator *ctxPointer to the asymmetric key generator instance.
Crypto_EncodingType typeEncoding type.
Crypto_DataBlob *pubKeyDataPointer to the public key data to convert.
Crypto_DataBlob *priKeyDataPointer to the private key data to convert.
OH_CryptoKeyPair **keyCtxPointer to the asymmetric key pair instance.

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

const char *OH_CryptoAsymKeyGenerator_GetAlgoName(OH_CryptoAsymKeyGenerator *ctx)

Description

Obtains the asymmetric key algorithm.

Since: 12

Parameters

NameDescription
OH_CryptoAsymKeyGenerator *ctxPointer to the asymmetric key generator instance.

Returns

TypeDescription
const char *Name of the asymmetric key algorithm obtained.

OH_CryptoAsymKeyGenerator_Destroy()

void OH_CryptoAsymKeyGenerator_Destroy(OH_CryptoAsymKeyGenerator *ctx)

Description

Destroys an asymmetric key generator instance.

Since: 12

Parameters

NameDescription
OH_CryptoAsymKeyGenerator *ctxPointer to the asymmetric key generator instance.

OH_CryptoKeyPair_Destroy()

void OH_CryptoKeyPair_Destroy(OH_CryptoKeyPair *keyCtx)

Description

Destroys an asymmetric key pair instance.

Since: 12

Parameters

NameDescription
OH_CryptoKeyPair *keyCtxPointer to the key pair instance.

OH_CryptoKeyPair_GetPubKey()

OH_CryptoPubKey *OH_CryptoKeyPair_GetPubKey(OH_CryptoKeyPair *keyCtx)

Description

Obtains the public key from a key pair.

Since: 12

Parameters

NameDescription
OH_CryptoKeyPair *keyCtxPointer to the key pair instance.

Returns

TypeDescription
OH_CryptoPubKey *Public key obtained.

OH_CryptoKeyPair_GetPrivKey()

OH_CryptoPrivKey *OH_CryptoKeyPair_GetPrivKey(OH_CryptoKeyPair *keyCtx)

Description

Obtains the private key of a key pair.

Since: 20

Parameters

NameDescription
OH_CryptoKeyPair *keyCtxPointer to the key pair instance.

Returns

TypeDescription
OH_CryptoPrivKey *Private 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.
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_CryptoPubKey *keyPonter to the public key data.
Crypto_EncodingType typeEncoding type.
const char *encodingStandardEncoding type.
Crypto_DataBlob *outPointer to the public key encoded in the specified format.

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_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.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 12

Parameters

NameDescription
OH_CryptoPubKey *keyPonter to the public key data.
CryptoAsymKey_ParamType itemType of the asymmetric key parameter to obtain.
Crypto_DataBlob *valuePointer to the parameter value 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_CryptoAsymKeyGenerator_SetPassword()

OH_Crypto_ErrCode OH_CryptoAsymKeyGenerator_SetPassword(OH_CryptoAsymKeyGenerator *ctx, const unsigned char *password, uint32_t passwordLen)

Description

Sets the password of the asymmetric key generator context.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeyGenerator *ctxPointer to the asymmetric encryption context.
const unsigned char *passwordPointer to the password.
uint32_t passwordLenPassword length.

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

OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_Create(OH_CryptoPrivKeyEncodingParams **ctx)

Description

Creates private key encoding parameters.
Note: The created resource must be destroyed by calling OH_CryptoPrivKeyEncodingParams_Destroy.

Since: 20

Parameters

NameDescription
OH_CryptoPrivKeyEncodingParams **ctxPointer to the private key encoding parameters.

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

OH_Crypto_ErrCode OH_CryptoPrivKeyEncodingParams_SetParam(OH_CryptoPrivKeyEncodingParams *ctx, CryptoPrivKeyEncoding_ParamType type, Crypto_DataBlob *value)

Description

Sets a private key encoding parameter.

Since: 20

Parameters

NameDescription
OH_CryptoPrivKeyEncodingParams *ctxPointer to the private key encoding parameters.
CryptoPrivKeyEncoding_ParamType typeParameter type for private key encoding.
Crypto_DataBlob *valuePointer to the parameter values for private key encoding.

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

void OH_CryptoPrivKeyEncodingParams_Destroy(OH_CryptoPrivKeyEncodingParams *ctx)

Description

Destroys a private key encoding parameter.

Since: 20

Parameters

NameDescription
OH_CryptoPrivKeyEncodingParams *ctxPointer to the private key encoding parameters.

OH_CryptoPrivKey_Encode()

OH_Crypto_ErrCode OH_CryptoPrivKey_Encode(OH_CryptoPrivKey *key, Crypto_EncodingType type, const char *encodingStandard, OH_CryptoPrivKeyEncodingParams *params, Crypto_DataBlob *out)

Description

Obtains the specified parameter from a private key instance.
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_CryptoPrivKey *keyPointer to the private key.
Crypto_EncodingType typePrivate key encoding type.
const char *encodingStandardPointer to the encoding standard,
for example, PKCS8.
OH_CryptoPrivKeyEncodingParams *paramsPointer to the private key encoding parameters, which can be NULL. Set this parameter if you need to encrypt a private key.
Crypto_DataBlob *outPointer to the encoding output.

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

OH_Crypto_ErrCode OH_CryptoPrivKey_GetParam(OH_CryptoPrivKey *key, CryptoAsymKey_ParamType item, Crypto_DataBlob *value)

Description

Obtains the specified parameter of a private key.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoPrivKey *keyPointer to the private key.
CryptoAsymKey_ParamType itemType of the asymmetric key parameter to obtain.
Crypto_DataBlob *valuePointer 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_CryptoAsymKeySpec_GenEcCommonParamsSpec()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenEcCommonParamsSpec(const char *curveName, OH_CryptoAsymKeySpec **spec)

Description

Generates EC common parameter specifications.
Note: After the use is complete, the memory for storing the spec parameter must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.

Since: 20

Parameters

NameDescription
const char *curveNamePointer to the ECC curve name.
OH_CryptoAsymKeySpec **specPointer to the EC common parameter 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_CryptoAsymKeySpec_GenDhCommonParamsSpec()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GenDhCommonParamsSpec(int pLen, int skLen, OH_CryptoAsymKeySpec **spec)

Description

Generates DH common parameter specifications.
Note: After the use is complete, the memory for storing the spec parameter must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.

Since: 20

Parameters

NameDescription
int pLenLength of the prime number p, in bytes.
int skLenLength of the private key, in bytes.
OH_CryptoAsymKeySpec **specPointer to the DH common parameter 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_CryptoAsymKeySpec_Create()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_Create(const char *algoName, CryptoAsymKeySpec_Type type, OH_CryptoAsymKeySpec **spec)

Description

Creates asymmetric key specifications based on the given algorithm name and specification type.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeySpec_Destroy.

Since: 20

Parameters

NameDescription
const char *algoNamePointer to the algorithm used to generate specifications.
For example, RSA.
CryptoAsymKeySpec_Type typeSpecification type of an asymmetric key.
OH_CryptoAsymKeySpec **specPointer to the asymmetric key 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_CryptoAsymKeySpec_SetParam()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, Crypto_DataBlob *value)

Description

Sets the specified parameters for asymmetric key specifications.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeySpec *specPointer to the asymmetric key specifications.
CryptoAsymKey_ParamType typeType of the asymmetric key parameter to obtain.
Crypto_DataBlob *valuePointer 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_CryptoAsymKeySpec_SetCommonParamsSpec()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_SetCommonParamsSpec(OH_CryptoAsymKeySpec *spec, OH_CryptoAsymKeySpec *commonParamsSpec)

Description

Sets the common parameter specifications for asymmetric key specifications.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeySpec *specPointer to the asymmetric key specifications.
OH_CryptoAsymKeySpec *commonParamsSpecCommon parameter 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_CryptoAsymKeySpec_GetParam()

OH_Crypto_ErrCode OH_CryptoAsymKeySpec_GetParam(OH_CryptoAsymKeySpec *spec, CryptoAsymKey_ParamType type, Crypto_DataBlob *value)

Description

Obtains the specified parameters for asymmetric key specifications.
Note: After the use is complete, the memory for storing the value parameter must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeySpec *specPointer to the asymmetric key specifications.
CryptoAsymKey_ParamType typeType of the asymmetric key parameter to obtain.
Crypto_DataBlob *valuePointer 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_CryptoAsymKeySpec_Destroy()

void OH_CryptoAsymKeySpec_Destroy(OH_CryptoAsymKeySpec *spec)

Description

Destroys asymmetric key specifications.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeySpec *specPointer to the asymmetric key specifications.

OH_CryptoAsymKeyGeneratorWithSpec_Create()

OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_Create(OH_CryptoAsymKeySpec *keySpec, OH_CryptoAsymKeyGeneratorWithSpec **generator)

Description

Creates a struct for an asymmetric key generator with specifications.
Note: The created resource must be destroyed by calling OH_CryptoAsymKeyGeneratorWithSpec_Destroy.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeySpec *keySpecPointer to the asymmetric key specifications.
OH_CryptoAsymKeyGeneratorWithSpec **generatorPointer to the asymmetric key generator with 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_CryptoAsymKeyGeneratorWithSpec_GenKeyPair()

OH_Crypto_ErrCode OH_CryptoAsymKeyGeneratorWithSpec_GenKeyPair(OH_CryptoAsymKeyGeneratorWithSpec *generator, OH_CryptoKeyPair **keyPair)

Description

Generates a key pair based on asymmetric key specifications.
Note: After the use is complete, the memory for storing the keyPair parameter must be released by calling OH_CryptoKeyPair_Destroy.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeyGeneratorWithSpec *generatorPointer to the asymmetric key generator with specifications.
OH_CryptoKeyPair **keyPairPointer to the key pair.

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

void OH_CryptoAsymKeyGeneratorWithSpec_Destroy(OH_CryptoAsymKeyGeneratorWithSpec *generator)

Description

Destroys a struct for an asymmetric key generator with specifications.

Since: 20

Parameters

NameDescription
OH_CryptoAsymKeyGeneratorWithSpec *generatorPointer to the asymmetric key generator with specifications.

OH_CryptoEcPoint_Create()

OH_Crypto_ErrCode OH_CryptoEcPoint_Create(const char *curveName, Crypto_DataBlob *ecKeyData, OH_CryptoEcPoint **point)

Description

Creates an EC point.
Note: The created resource must be destroyed by calling OH_CryptoEcPoint_Destroy.

Since: 20

Parameters

NameDescription
const char *curveNamePointer to the curve name.
Crypto_DataBlob *ecKeyDataPointer to the EC point data, in 04 ||x ||y, 02 ||x, or 03 ||x format. If ecKeyData is NULL, an empty EC point specification is created.
OH_CryptoEcPoint **pointPointer to the EC point.

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

OH_Crypto_ErrCode OH_CryptoEcPoint_GetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y)

Description

Obtains the X and Y coordinates of an EC point.
Note: After the use is complete, the memory for storing the x and y parameters must be released by calling OH_Crypto_FreeDataBlob.

Since: 20

Parameters

NameDescription
OH_CryptoEcPoint *pointPointer to the EC point.
Crypto_DataBlob *xPointer to the X coordinate of an EC point. The value can be NULL.
Crypto_DataBlob *yPointer to the Y coordinate of an EC point. The value can be NULL.

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

OH_Crypto_ErrCode OH_CryptoEcPoint_SetCoordinate(OH_CryptoEcPoint *point, Crypto_DataBlob *x, Crypto_DataBlob *y)

Description

Sets the X and Y coordinates of an EC point.

Since: 20

Parameters

NameDescription
OH_CryptoEcPoint *pointPointer to the EC point.
Crypto_DataBlob *xPointer to the X coordinate of the EC point.
Crypto_DataBlob *yPointer to the Y coordinate of the EC point.

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

OH_Crypto_ErrCode OH_CryptoEcPoint_Encode(OH_CryptoEcPoint *point, const char *format, Crypto_DataBlob *out)

Description

Encodes an EC point in a specified format.
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_CryptoEcPoint *pointPointer to the EC point.
const char *formatPointer to the encoding format. The value can be UNCOMPRESSED or COMPRESSED.
Crypto_DataBlob *outPointer to the encoded EC point 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_CryptoEcPoint_Destroy()

void OH_CryptoEcPoint_Destroy(OH_CryptoEcPoint *point)

Description

Destroys an EC point.

Since: 20

Parameters

NameDescription
OH_CryptoEcPoint *pointPointer to the EC point.

你可能感兴趣的鸿蒙文章

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