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
23 #include <dpl/crypto_hash.h>
29 std::cout << "Invalid parameters: crypto_hash [hash_function] [message]" << std::endl;
30 std::cout << "hash_function is one of following: MD2, MD4, MD5, SHA, SHA1, DSS, DSS1, ECDSA, SHA224, SHA256, SHA384, SHA512" << std::endl;
33 int main(int argc, char *argv[])
41 DPL::Crypto::Hash::Base *crypto;
42 std::string algorithm = argv[1];
44 if (algorithm == "MD2")
45 crypto = new DPL::Crypto::Hash::MD2();
46 else if (algorithm == "MD4")
47 crypto = new DPL::Crypto::Hash::MD4();
48 else if (algorithm == "MD5")
49 crypto = new DPL::Crypto::Hash::MD5();
50 else if (algorithm == "SHA")
51 crypto = new DPL::Crypto::Hash::SHA();
52 else if (algorithm == "SHA1")
53 crypto = new DPL::Crypto::Hash::SHA1();
54 else if (algorithm == "DSS")
55 crypto = new DPL::Crypto::Hash::DSS();
56 else if (algorithm == "DSS1")
57 crypto = new DPL::Crypto::Hash::DSS1();
58 else if (algorithm == "ECDSA")
59 crypto = new DPL::Crypto::Hash::ECDSA();
60 else if (algorithm == "SHA224")
61 crypto = new DPL::Crypto::Hash::SHA224();
62 else if (algorithm == "SHA256")
63 crypto = new DPL::Crypto::Hash::SHA256();
64 else if (algorithm == "SHA384")
65 crypto = new DPL::Crypto::Hash::SHA384();
66 else if (algorithm == "SHA512")
67 crypto = new DPL::Crypto::Hash::SHA512();
74 crypto->Append(argv[2]);
77 std::cout << crypto->ToString() << std::endl;