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.
17 * @file crypto_hash.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of crypto hash example
22 #include <dpl/crypto_hash.h>
28 std::cout << "Invalid parameters: crypto_hash [hash_function] [message]" << std::endl;
29 std::cout << "hash_function is one of following: MD2, MD4, MD5, SHA, SHA1, DSS, DSS1, ECDSA, SHA224, SHA256, SHA384, SHA512" << std::endl;
32 int main(int argc, char *argv[])
40 DPL::Crypto::Hash::Base *crypto;
41 std::string algorithm = argv[1];
43 if (algorithm == "MD2")
44 crypto = new DPL::Crypto::Hash::MD2();
45 else if (algorithm == "MD4")
46 crypto = new DPL::Crypto::Hash::MD4();
47 else if (algorithm == "MD5")
48 crypto = new DPL::Crypto::Hash::MD5();
49 else if (algorithm == "SHA")
50 crypto = new DPL::Crypto::Hash::SHA();
51 else if (algorithm == "SHA1")
52 crypto = new DPL::Crypto::Hash::SHA1();
53 else if (algorithm == "DSS")
54 crypto = new DPL::Crypto::Hash::DSS();
55 else if (algorithm == "DSS1")
56 crypto = new DPL::Crypto::Hash::DSS1();
57 else if (algorithm == "ECDSA")
58 crypto = new DPL::Crypto::Hash::ECDSA();
59 else if (algorithm == "SHA224")
60 crypto = new DPL::Crypto::Hash::SHA224();
61 else if (algorithm == "SHA256")
62 crypto = new DPL::Crypto::Hash::SHA256();
63 else if (algorithm == "SHA384")
64 crypto = new DPL::Crypto::Hash::SHA384();
65 else if (algorithm == "SHA512")
66 crypto = new DPL::Crypto::Hash::SHA512();
73 crypto->Append(argv[2]);
76 std::cout << crypto->ToString() << std::endl;