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
23namespace OHOS {
24namespace DistributedHardware {
25class Crypto {
26public:
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    static int32_t GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash);
37#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
38    static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash,
39        DmKVValue &kvValue);
40    static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash,
41        DmKVValue &kvValue);
42    static int32_t GetAnoyDeviceInfo(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue);
43    static int32_t ConvertUdidHashToAnoyGenerate(const std::string &appId, const std::string &udidHash,
44        DmKVValue &kvValue);
45#endif
46};
47} // namespace DistributedHardware
48} // namespace OHOS
49#endif // OHOS_DM_CRYPTO_H
50