• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 void DmGenerateStrHash(const void *data, size_t dataSize, unsigned char *outBuf, uint32_t outBufLen,
28         uint32_t startIndex);
29     static std::string Sha256(const std::string &text, bool isUpper = false);
30     static std::string Sha256(const void *data, size_t size, bool isUpper = false);
31     static int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen,
32         const char *inBuf, uint32_t inLen);
33     static int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash);
34     static std::string GetGroupIdHash(const std::string &groupId);
35     static int32_t GetSecRandom(uint8_t *out, size_t outLen);
36     static std::string GetSecSalt();
37     static std::string GetHashWithSalt(const std::string &text, const std::string &salt);
38     static int32_t GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash);
39     static int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen,
40         const unsigned char *inBuf, uint32_t inLen);
41 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
42     static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash,
43         DmKVValue &kvValue);
44     static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash,
45         DmKVValue &kvValue);
46     static int32_t GetAnoyDeviceInfo(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue);
47     static int32_t ConvertUdidHashToAnoyGenerate(const std::string &appId, const std::string &udidHash,
48         DmKVValue &kvValue);
49 #endif
50 };
51 } // namespace DistributedHardware
52 } // namespace OHOS
53 #endif // OHOS_DM_CRYPTO_H
54