1 /* 2 * Copyright (C) 2024 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 #ifndef TEL_AES_CRYPTO_UTILS_H 17 #define TEL_AES_CRYPTO_UTILS_H 18 19 #include <string> 20 21 #include "hks_api.h" 22 #include "hks_param.h" 23 #include "hks_type.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 class TelAesCryptoUtils { 28 public: 29 static std::string AesCryptoEncrypt(const std::string &srcData); 30 static std::string AesCryptoDecrypt(std::string &srcData); 31 static int SaveEncryptString(const std::string &key, int32_t id, const std::string &rawData); 32 static std::string ObtainDecryptString(const std::string &key, int32_t id, const std::string &defValue); 33 34 private: 35 static int32_t InitParamSet(struct HksParamSet **paramSet, const struct HksParam *params, uint32_t paramCount); 36 static std::string AesCryptoEncryptInner(const struct HksBlob *keyAlias, struct HksParamSet *genParamSet, 37 struct HksParamSet *encryptParamSet, const std::string &srcData); 38 static std::string AesCryptoDecryptInner(const struct HksBlob *keyAlias, 39 struct HksParamSet *decryptGcmParamSet, std::string &srcData); 40 static int32_t AesCryptoLoopUpdate(const struct HksBlob *handle, const struct HksParamSet *paramSet, 41 const struct HksBlob *inData, struct HksBlob *outData); 42 static bool HexToDec(char hex, uint8_t &decodeValue); 43 static std::string DecToHexString(const uint8_t *data, size_t len); 44 static std::pair<uint8_t *, size_t> HexToDecString(const std::string &hexString); 45 }; 46 } // namespace Telephony 47 } // namespace OHOS 48 #endif // TEL_AES_CRYPTO_UTILS_H