static Botan::AutoSeeded_RNG rng;
-namespace fides {
- /// \class privatekey
+namespace Fides {
+ /// \class PrivateKey
///
/// \brief Representation of a public/private keypair.
///
/// so that others who have the corresponding public key
/// can ascertain that the statement was really made by us.
- privatekey::privatekey(): priv(0) {
+ PrivateKey::PrivateKey(): priv(0) {
}
- privatekey::~privatekey() {
+ PrivateKey::~PrivateKey() {
delete priv;
pub = 0;
}
/// Generates a new public/private keypair.
//
/// @param field OID of the field to generate a key in.
- void privatekey::generate(const std::string &field) {
+ void PrivateKey::generate(const std::string &field) {
Botan::EC_Domain_Params domain = Botan::get_EC_Dom_Pars_by_oid(field);
pub = priv = new Botan::ECDSA_PrivateKey(rng, domain);
}
/// Allowed values are 112, 128, 160, 192, 224, 256, 384 and 521.
/// Keys less than 160 bits are considered weak.
/// Keys greater than 224 bits are considered very strong.
- void privatekey::generate(unsigned int bits) {
+ void PrivateKey::generate(unsigned int bits) {
switch(bits) {
case 112: return generate("1.3.132.0.6");
case 128: return generate("1.3.132.0.28");
case 256: return generate("1.3.132.0.10");
case 384: return generate("1.3.132.0.34");
case 521: return generate("1.3.132.0.35");
- default: throw fides::exception("Unsupported number of bits for private key");
+ default: throw Fides::exception("Unsupported number of bits for private key");
}
}
/// Loads a private key from a stream.
//
/// @param in Stream to read from.
- void privatekey::load_private(std::istream &in) {
+ void PrivateKey::load_private(std::istream &in) {
try {
Botan::DataSource_Stream stream(in);
pub = priv = dynamic_cast<Botan::ECDSA_PrivateKey *>(Botan::PKCS8::load_key(stream, rng, ""));
} catch(Botan::Exception &e) {
- throw fides::exception(e.what());
+ throw Fides::exception(e.what());
}
}
/// Loads a private key from a file.
//
/// @param filename Name of the file to read from.
- void privatekey::load_private(const std::string &filename) {
+ void PrivateKey::load_private(const std::string &filename) {
ifstream in(filename.c_str());
load_private(in);
}
/// Saves the private key to a stream.
//
/// @param out Stream to write to.
- void privatekey::save_private(std::ostream &out) const {
+ void PrivateKey::save_private(std::ostream &out) const {
out << Botan::PKCS8::PEM_encode(*priv);
}
/// Saves the private key to a file.
//
/// @param filename Name of the file to write to.
- void privatekey::save_private(const std::string &filename) const {
+ void PrivateKey::save_private(const std::string &filename) const {
ofstream out(filename.c_str());
save_private(out);
}
//
/// @param statement The statement that is to be signed.
/// @return A string containing the signature.
- string privatekey::sign(const std::string &statement) const {
+ string PrivateKey::sign(const std::string &statement) const {
auto_ptr<Botan::PK_Signer> signer(Botan::get_pk_signer(*priv, "EMSA1(SHA-512)"));
Botan::SecureVector<Botan::byte> sig = signer->sign_message((const Botan::byte *)statement.data(), statement.size(), rng);
return string((const char *)sig.begin(), (size_t)sig.size());