1 /* 2 * Copyright (c) 2023 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 OHOS_DM_CRYPTO_H 17 #define OHOS_DM_CRYPTO_H 18 #include <string> 19 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 20 #include "dm_kv_info.h" 21 #endif 22 23 namespace OHOS { 24 namespace DistributedHardware { 25 class Crypto { 26 public: 27 static std::string Sha256(const std::string &text, bool isUpper = false); 28 static std::string Sha256(const void *data, size_t size, bool isUpper = false); 29 static int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, 30 const char *inBuf, uint32_t inLen); 31 static int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash); 32 static std::string GetGroupIdHash(const std::string &groupId); 33 static int32_t GetSecRandom(uint8_t *out, size_t outLen); 34 static std::string GetSecSalt(); 35 static std::string GetHashWithSalt(const std::string &text, const std::string &salt); 36 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 37 static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash, 38 DmKVValue &kvValue); 39 static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash, 40 DmKVValue &kvValue); 41 static int32_t GetAnoyDeviceInfo(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue); 42 static int32_t ConvertUdidHashToAnoyGenerate(const std::string &appId, const std::string &udidHash, 43 DmKVValue &kvValue); 44 #endif 45 }; 46 } // namespace DistributedHardware 47 } // namespace OHOS 48 #endif // OHOS_DM_CRYPTO_H 49