1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Prerequisites/BsPrerequisitesUtil.h"
4#include "ThirdParty/md5.h"
5
6namespace bs
7{
8 String md5(const WString& source)
9 {
10 MD5 md5;
11 md5.update((UINT8*)source.data(), (UINT32)source.length() * sizeof(WString::value_type));
12 md5.finalize();
13
14 UINT8 digest[16];
15 md5.decdigest(digest, sizeof(digest));
16
17 String buf;
18 buf.resize(32);
19 for (int i = 0; i < 16; i++)
20 snprintf(&(buf[0]) + i * 2, 3, "%02x", digest[i]);
21
22 return buf;
23 }
24
25 String md5(const String& source)
26 {
27 MD5 md5;
28 md5.update((UINT8*)source.data(), (UINT32)source.length() * sizeof(String::value_type));
29 md5.finalize();
30
31 UINT8 digest[16];
32 md5.decdigest(digest, sizeof(digest));
33
34 String buf;
35 buf.resize(32);
36 for (int i = 0; i < 16; i++)
37 snprintf(&(buf[0]) + i * 2, 3, "%02x", digest[i]);
38
39 return buf;
40 }
41}
42