2
Grab an DSA public key from the file given as an argument, grab a signature
3
from another file, and verify the message (which, suprise, is also in a file).
5
The signature format isn't particularly standard, but it's not bad. It's simply
6
the IEEE 1363 signature format, encoded into base64 with a trailing newline
8
Written by Jack Lloyd (lloyd@randombit.net), August 5, 2002
9
Updated to use X.509 format keys, October 21, 2002
11
This file is in the public domain
20
#include <botan/botan.h>
21
#include <botan/look_pk.h>
22
#include <botan/dsa.h>
23
using namespace Botan;
25
SecureVector<byte> b64_decode(const std::string& in)
27
Pipe pipe(new Base64_Decoder);
29
return pipe.read_all();
32
int main(int argc, char* argv[])
36
std::cout << "Usage: " << argv[0]
37
<< " keyfile messagefile sigfile" << std::endl;
41
std::ifstream message(argv[2]);
44
std::cout << "Couldn't read the message file." << std::endl;
48
std::ifstream sigfile(argv[3]);
51
std::cout << "Couldn't read the signature file." << std::endl;
57
getline(sigfile, sigstr);
59
LibraryInitializer init;
61
std::auto_ptr<X509_PublicKey> key(X509::load_key(argv[1]));
62
DSA_PublicKey* dsakey = dynamic_cast<DSA_PublicKey*>(key.get());
65
std::cout << "The loaded key is not a DSA key!\n";
69
SecureVector<byte> sig = b64_decode(sigstr);
71
Pipe pipe(new PK_Verifier_Filter(
72
get_pk_verifier(*dsakey, "EMSA1(SHA-1)"), sig
84
std::cout << "Signature verified\n";
86
std::cout << "Signature did NOT verify\n";
88
catch(std::exception& e)
90
std::cout << "Exception caught: " << e.what() << std::endl;