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
| Name | typedef Keyword | Description |
|---|---|---|
| OH_CryptoKeyPair | OH_CryptoKeyPair | Defines a struct for an asymmetric key pair. |
| OH_CryptoPubKey | OH_CryptoPubKey | Defines a struct for the public key in an asymmetric key pair. |
| OH_CryptoPrivKey | OH_CryptoPrivKey | Defines a struct for a private key. |
| OH_CryptoAsymKeyGenerator | OH_CryptoAsymKeyGenerator | Defines a struct for an asymmetric key generator. |
| OH_CryptoPrivKeyEncodingParams | OH_CryptoPrivKeyEncodingParams | Defines a struct for private key encoding parameters. |
| OH_CryptoAsymKeySpec | OH_CryptoAsymKeySpec | Defines a struct for asymmetric key specifications. |
| OH_CryptoAsymKeyGeneratorWithSpec | OH_CryptoAsymKeyGeneratorWithSpec | Defines a struct for an asymmetric key generator with specifications. |
| OH_CryptoEcPoint | OH_CryptoEcPoint | Defines a struct for an EC point. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| CryptoAsymKey_ParamType | CryptoAsymKey_ParamType | Enumerates the types of the asymmetric key parameters. |
| Crypto_EncodingType | Crypto_EncodingType | Enumerates the encoding types. |
| CryptoPrivKeyEncoding_ParamType | CryptoPrivKeyEncoding_ParamType | Defines the parameter type for private key encoding. |
| CryptoAsymKeySpec_Type | CryptoAsymKeySpec_Type | Defines the specification type of an asymmetric key. |
Functions
Enum Description
CryptoAsymKey_ParamType
enum CryptoAsymKey_ParamType
Description
Enumerates the types of the asymmetric key parameters.
Since: 12
| Enum Item | Description |
|---|---|
| CRYPTO_DSA_P_DATABLOB = 101 | Prime modulus p in the DSA algorithm. |
| CRYPTO_DSA_Q_DATABLOB = 102 | Parameter q, prime factor of (p – 1) in the DSA algorithm. |
| CRYPTO_DSA_G_DATABLOB = 103 | Parameter g in the DSA algorithm. |
| CRYPTO_DSA_SK_DATABLOB = 104 | Private key sk in the DSA algorithm. |
| CRYPTO_DSA_PK_DATABLOB = 105 | Public key pk in the DSA algorithm. |
| CRYPTO_ECC_FP_P_DATABLOB = 201 | Prime number p in the Fp field of the elliptic curve in the ECC algorithm. |
| CRYPTO_ECC_A_DATABLOB = 202 | First coefficient a of the elliptic curve in the ECC algorithm. |
| CRYPTO_ECC_B_DATABLOB = 203 | Second coefficient b of the elliptic curve in the ECC algorithm. |
| CRYPTO_ECC_G_X_DATABLOB = 204 | X coordinate of the base point g in the ECC algorithm. |
| CRYPTO_ECC_G_Y_DATABLOB = 205 | Y coordinate of the base point g in the ECC algorithm. |
| CRYPTO_ECC_N_DATABLOB = 206 | Order n of the base point g in the ECC algorithm. |
| CRYPTO_ECC_H_INT = 207 | Cofactor h in the ECC algorithm. |
| CRYPTO_ECC_SK_DATABLOB = 208 | Private key sk in the ECC algorithm. |
| CRYPTO_ECC_PK_X_DATABLOB = 209 | X coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm. |
| CRYPTO_ECC_PK_Y_DATABLOB = 210 | Y coordinate of the public key pk (a point on the elliptic curve) in the ECC algorithm. |
| CRYPTO_ECC_FIELD_TYPE_STR = 211 | Elliptic curve field type in the ECC algorithm. Currently, only the Fp field is supported. |
| CRYPTO_ECC_FIELD_SIZE_INT = 212 | Size 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 = 213 | Standards for Efficient Cryptography Group (SECG) curve name in the ECC algorithm. |
| CRYPTO_RSA_N_DATABLOB = 301 | Modulus n in the RSA algorithm. |
| CRYPTO_RSA_D_DATABLOB = 302 | Private key sk (private key exponent d) in the RSA algorithm. |
| CRYPTO_RSA_E_DATABLOB = 303 | Public key pk (public key exponent e) in the RSA algorithm. |
| CRYPTO_DH_P_DATABLOB = 401 | Prime p in the DH algorithm. |
| CRYPTO_DH_G_DATABLOB = 402 | Parameter g in the DH algorithm. |
| CRYPTO_DH_L_INT = 403 | Length of the private key in the DH algorithm, in bits. |
| CRYPTO_DH_SK_DATABLOB = 404 | Private key sk in the DH algorithm. |
| CRYPTO_DH_PK_DATABLOB = 405 | Public key pk in the DH algorithm. |
| CRYPTO_ED25519_SK_DATABLOB = 501 | Private key sk in the Ed25519 algorithm. |
| CRYPTO_ED25519_PK_DATABLOB = 502 | Public key pk in the Ed25519 algorithm. |
| CRYPTO_X25519_SK_DATABLOB = 601 | Private key sk in the X25519 algorithm. |
| CRYPTO_X25519_PK_DATABLOB = 602 | Public key pk in the X25519 algorithm. |
Crypto_EncodingType
enum Crypto_EncodingType
Description
Enumerates the encoding types.
Since: 12
| Enum Item | Description |
|---|---|
| CRYPTO_PEM = 0 | PEM. |
| CRYPTO_DER = 1 | DER. |
CryptoPrivKeyEncoding_ParamType
enum CryptoPrivKeyEncoding_ParamType
Description
Defines the parameter type for private key encoding.
Since: 20
| Enum Item | Description |
|---|---|
| CRYPTO_PRIVATE_KEY_ENCODING_PASSWORD_STR = 0 | Password string. |
| CRYPTO_PRIVATE_KEY_ENCODING_SYMMETRIC_CIPHER_STR = 1 | Symmetric cipher string. |
CryptoAsymKeySpec_Type
enum CryptoAsymKeySpec_Type
Description
Defines the specification type of an asymmetric key.
Since: 20
| Enum Item | Description |
|---|---|
| CRYPTO_ASYM_KEY_COMMON_PARAMS_SPEC = 0 | Common parameter specifications. |
| CRYPTO_ASYM_KEY_PRIVATE_KEY_SPEC = 1 | Private key specifications. |
| CRYPTO_ASYM_KEY_PUBLIC_KEY_SPEC = 2 | Public key specifications. |
| CRYPTO_ASYM_KEY_KEY_PAIR_SPEC = 3 | Key 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
| Name | Description |
|---|---|
| const char *algoName | Pointer the algorithm used to create a generator. For example, RSA1024|PRIMES_2. |
| OH_CryptoAsymKeyGenerator **ctx | Pointer to the asymmetric key generator context created. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGenerator *ctx | Pointer to the asymmetric key generator instance. |
| OH_CryptoKeyPair **keyCtx | Pointer to the asymmetric key pair instance. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGenerator *ctx | Pointer to the asymmetric key generator instance. |
| Crypto_EncodingType type | Encoding type. |
| Crypto_DataBlob *pubKeyData | Pointer to the public key data to convert. |
| Crypto_DataBlob *priKeyData | Pointer to the private key data to convert. |
| OH_CryptoKeyPair **keyCtx | Pointer to the asymmetric key pair instance. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGenerator *ctx | Pointer to the asymmetric key generator instance. |
Returns
| Type | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGenerator *ctx | Pointer 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
| Name | Description |
|---|---|
| OH_CryptoKeyPair *keyCtx | Pointer 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
| Name | Description |
|---|---|
| OH_CryptoKeyPair *keyCtx | Pointer to the key pair instance. |
Returns
| Type | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| OH_CryptoKeyPair *keyCtx | Pointer to the key pair instance. |
Returns
| Type | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| OH_CryptoPubKey *key | Ponter to the public key data. |
| Crypto_EncodingType type | Encoding type. |
| const char *encodingStandard | Encoding type. |
| Crypto_DataBlob *out | Pointer to the public key encoded in the specified format. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoPubKey *key | Ponter to the public key data. |
| CryptoAsymKey_ParamType item | Type of the asymmetric key parameter to obtain. |
| Crypto_DataBlob *value | Pointer to the parameter value obtained. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGenerator *ctx | Pointer to the asymmetric encryption context. |
| const unsigned char *password | Pointer to the password. |
| uint32_t passwordLen | Password length. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoPrivKeyEncodingParams **ctx | Pointer to the private key encoding parameters. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoPrivKeyEncodingParams *ctx | Pointer to the private key encoding parameters. |
| CryptoPrivKeyEncoding_ParamType type | Parameter type for private key encoding. |
| Crypto_DataBlob *value | Pointer to the parameter values for private key encoding. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoPrivKeyEncodingParams *ctx | Pointer 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
| Name | Description |
|---|---|
| OH_CryptoPrivKey *key | Pointer to the private key. |
| Crypto_EncodingType type | Private key encoding type. |
| const char *encodingStandard | Pointer to the encoding standard, for example, PKCS8. |
| OH_CryptoPrivKeyEncodingParams *params | Pointer to the private key encoding parameters, which can be NULL. Set this parameter if you need to encrypt a private key. |
| Crypto_DataBlob *out | Pointer to the encoding output. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoPrivKey *key | Pointer to the private key. |
| CryptoAsymKey_ParamType item | Type of the asymmetric key parameter to obtain. |
| Crypto_DataBlob *value | Pointer to the output data. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| const char *curveName | Pointer to the ECC curve name. |
| OH_CryptoAsymKeySpec **spec | Pointer to the EC common parameter specifications. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| int pLen | Length of the prime number p, in bytes. |
| int skLen | Length of the private key, in bytes. |
| OH_CryptoAsymKeySpec **spec | Pointer to the DH common parameter specifications. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| const char *algoName | Pointer to the algorithm used to generate specifications. For example, RSA. |
| CryptoAsymKeySpec_Type type | Specification type of an asymmetric key. |
| OH_CryptoAsymKeySpec **spec | Pointer to the asymmetric key specifications. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeySpec *spec | Pointer to the asymmetric key specifications. |
| CryptoAsymKey_ParamType type | Type of the asymmetric key parameter to obtain. |
| Crypto_DataBlob *value | Pointer to the input data. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeySpec *spec | Pointer to the asymmetric key specifications. |
| OH_CryptoAsymKeySpec *commonParamsSpec | Common parameter specifications. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeySpec *spec | Pointer to the asymmetric key specifications. |
| CryptoAsymKey_ParamType type | Type of the asymmetric key parameter to obtain. |
| Crypto_DataBlob *value | Pointer to the output data. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeySpec *spec | Pointer 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
| Name | Description |
|---|---|
| OH_CryptoAsymKeySpec *keySpec | Pointer to the asymmetric key specifications. |
| OH_CryptoAsymKeyGeneratorWithSpec **generator | Pointer to the asymmetric key generator with specifications. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGeneratorWithSpec *generator | Pointer to the asymmetric key generator with specifications. |
| OH_CryptoKeyPair **keyPair | Pointer to the key pair. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoAsymKeyGeneratorWithSpec *generator | Pointer 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
| Name | Description |
|---|---|
| const char *curveName | Pointer to the curve name. |
| Crypto_DataBlob *ecKeyData | Pointer 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 **point | Pointer to the EC point. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoEcPoint *point | Pointer to the EC point. |
| Crypto_DataBlob *x | Pointer to the X coordinate of an EC point. The value can be NULL. |
| Crypto_DataBlob *y | Pointer to the Y coordinate of an EC point. The value can be NULL. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoEcPoint *point | Pointer to the EC point. |
| Crypto_DataBlob *x | Pointer to the X coordinate of the EC point. |
| Crypto_DataBlob *y | Pointer to the Y coordinate of the EC point. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoEcPoint *point | Pointer to the EC point. |
| const char *format | Pointer to the encoding format. The value can be UNCOMPRESSED or COMPRESSED. |
| Crypto_DataBlob *out | Pointer to the encoded EC point data. |
Returns
| Type | Description |
|---|---|
| OH_Crypto_ErrCode | CRYPTO_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
| Name | Description |
|---|---|
| OH_CryptoEcPoint *point | Pointer 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