• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 // [Start generate_3des_key]
17 #include "CryptoArchitectureKit/crypto_common.h"
18 #include "CryptoArchitectureKit/crypto_sym_key.h"
19 #include "file.h"
20 
doTestDataCovertSymKey()21 OH_Crypto_ErrCode doTestDataCovertSymKey()
22 {
23     const char *algName = "3DES192";
24     OH_CryptoSymKeyGenerator *ctx = nullptr;
25     OH_CryptoSymKey *convertKeyCtx = nullptr;
26     Crypto_DataBlob out = {.data = nullptr, .len = 0};
27     OH_Crypto_ErrCode ret;
28     uint8_t arr[] = {0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, 0xad, 0x47, 0xfc, 0x5a,
29                      0x46, 0x39, 0xee, 0x7c, 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72};
30     Crypto_DataBlob convertBlob = {.data = arr, .len = sizeof(arr)};
31     ret = OH_CryptoSymKeyGenerator_Create(algName, &ctx);
32     if (ret != CRYPTO_SUCCESS) {
33         return ret;
34     }
35     ret = OH_CryptoSymKeyGenerator_Convert(ctx, &convertBlob, &convertKeyCtx);
36     if (ret != CRYPTO_SUCCESS) {
37         OH_CryptoSymKeyGenerator_Destroy(ctx);
38         return ret;
39     }
40     ret = OH_CryptoSymKey_GetKeyData(convertKeyCtx, &out);
41     OH_CryptoSymKeyGenerator_Destroy(ctx);
42     OH_CryptoSymKey_Destroy(convertKeyCtx);
43     if (ret != CRYPTO_SUCCESS) {
44         return ret;
45     }
46     OH_Crypto_FreeDataBlob(&out);
47     return ret;
48 }
49 // [End generate_3des_key]
50 
51