PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/external/md5wrapper.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 50 lines | 21 code | 8 blank | 21 comment | 1 complexity | ec54a8ff5b0118e5382a6f17db6ec761 MD5 | raw file
  1. /*
  2. * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file src/external/md5wrapper.cpp
  18. * @author Bartlomiej Grzelewski <b.grzelewski@samsung.com>
  19. * @version 1.0
  20. * @brief Wrapper for md5.h
  21. */
  22. #include <cstdint>
  23. #include <iomanip>
  24. #include <sstream>
  25. #include <string>
  26. #include <vector>
  27. #include <md5wrapper.h>
  28. #include <md5.h>
  29. namespace Cynara {
  30. const std::string generateMD5(const std::string &data) {
  31. MD5Context context;
  32. std::vector<u_int8_t> result(MD5_DIGEST_LENGTH);
  33. MD5Init(&context);
  34. MD5Update(&context, reinterpret_cast<const u_int8_t *>(data.data()), data.size());
  35. MD5Final(result.data(), &context);
  36. std::stringstream output;
  37. output << std::setfill('0') << std::hex;
  38. for (auto e : result)
  39. output << std::setw(2) << static_cast<int>(e);
  40. return output.str();
  41. }
  42. } // namespace Cynara