/* * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "crypto.h" #include #include #include #include #include "common/sharing_log.h" namespace OHOS { namespace Sharing { std::vector GenerateSha256HashId(const uint8_t *originalId, uint32_t &len) { if (originalId == nullptr || len == 0) { return std::vector{}; } std::unique_ptr outHash = std::make_unique(len); uint32_t outLen = 0; // should be 32 bytes int32_t ret = EVP_Digest(originalId, len, outHash.get(), &outLen, EVP_sha256(), nullptr); if (ret != 1) { SHARING_LOGE("Get Openssl Hash fail, %{public}d", ret); return std::vector{}; } std::vector result(outHash.get(), outHash.get() + outLen); return result; } } // namespace Sharing } // namespace OHOS