1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include "crypto.h" 17 #include <iomanip> 18 #include <sstream> 19 20 namespace OHOS { 21 namespace Sharing { 22 GetMD5(const std::string &src)23std::string GetMD5(const std::string &src) 24 { 25 int md5DigestLength = 4; 26 unsigned char MD5Hash[md5DigestLength]; 27 std::string MD5Digest; 28 std::string tmp; 29 std::stringstream ss; 30 31 for (int32_t i = 0; i < md5DigestLength; ++i) { 32 ss << std::hex << std::setw(2) << std::setfill('0') << (int32_t)MD5Hash[i] << std::endl; // 2: fix offset 33 ss >> tmp; 34 MD5Digest += tmp; 35 } 36 37 return MD5Digest; 38 } 39 40 } // namespace Sharing 41 } // namespace OHOS