2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file AceDaoConversions.h
20 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
21 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
26 #include <openssl/md5.h>
27 #include <dpl/foreach.h>
29 #include <dpl/ace-dao-ro/AceDAOConversions.h>
33 DPL::String AceDaoConversions::convertToHash(const BaseAttributeSet &attributes)
35 unsigned char attrHash[MD5_DIGEST_LENGTH];
36 std::string attrString;
37 FOREACH(it, attributes) {
38 // [CR] implementation of it->toString() is not secure, 24.03.2010
39 attrString.append((*it)->toString());
42 MD5((unsigned char *) attrString.c_str(), attrString.length(), attrHash);
44 char attrHashCoded[MD5_DIGEST_LENGTH*2 + 1];
45 for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
46 sprintf(&attrHashCoded[i << 1],
48 static_cast<int>(attrHash[i]));
50 return DPL::FromASCIIString(attrHashCoded);