179a732c7Sopenharmony_ci/*
279a732c7Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License.
579a732c7Sopenharmony_ci * You may obtain a copy of the License at
679a732c7Sopenharmony_ci *
779a732c7Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
879a732c7Sopenharmony_ci *
979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and
1379a732c7Sopenharmony_ci * limitations under the License.
1479a732c7Sopenharmony_ci */
1579a732c7Sopenharmony_ci
1679a732c7Sopenharmony_ci#ifndef OHOS_DM_CRYPTO_H
1779a732c7Sopenharmony_ci#define OHOS_DM_CRYPTO_H
1879a732c7Sopenharmony_ci#include <string>
1979a732c7Sopenharmony_ci#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
2079a732c7Sopenharmony_ci#include "dm_kv_info.h"
2179a732c7Sopenharmony_ci#endif
2279a732c7Sopenharmony_ci
2379a732c7Sopenharmony_cinamespace OHOS {
2479a732c7Sopenharmony_cinamespace DistributedHardware {
2579a732c7Sopenharmony_ciclass Crypto {
2679a732c7Sopenharmony_cipublic:
2779a732c7Sopenharmony_ci    static std::string Sha256(const std::string &text, bool isUpper = false);
2879a732c7Sopenharmony_ci    static std::string Sha256(const void *data, size_t size, bool isUpper = false);
2979a732c7Sopenharmony_ci    static int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen,
3079a732c7Sopenharmony_ci        const char *inBuf, uint32_t inLen);
3179a732c7Sopenharmony_ci    static int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash);
3279a732c7Sopenharmony_ci    static std::string GetGroupIdHash(const std::string &groupId);
3379a732c7Sopenharmony_ci    static int32_t GetSecRandom(uint8_t *out, size_t outLen);
3479a732c7Sopenharmony_ci    static std::string GetSecSalt();
3579a732c7Sopenharmony_ci    static std::string GetHashWithSalt(const std::string &text, const std::string &salt);
3679a732c7Sopenharmony_ci    static int32_t GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash);
3779a732c7Sopenharmony_ci#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
3879a732c7Sopenharmony_ci    static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash,
3979a732c7Sopenharmony_ci        DmKVValue &kvValue);
4079a732c7Sopenharmony_ci    static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash,
4179a732c7Sopenharmony_ci        DmKVValue &kvValue);
4279a732c7Sopenharmony_ci    static int32_t GetAnoyDeviceInfo(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue);
4379a732c7Sopenharmony_ci    static int32_t ConvertUdidHashToAnoyGenerate(const std::string &appId, const std::string &udidHash,
4479a732c7Sopenharmony_ci        DmKVValue &kvValue);
4579a732c7Sopenharmony_ci#endif
4679a732c7Sopenharmony_ci};
4779a732c7Sopenharmony_ci} // namespace DistributedHardware
4879a732c7Sopenharmony_ci} // namespace OHOS
4979a732c7Sopenharmony_ci#endif // OHOS_DM_CRYPTO_H
50