-}
-
-/// Loads a private key from a file.
-//
-/// @param filename Name of the file to read from.
-void fides::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 fides::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 fides::privatekey::save_private(const std::string &filename) const {
- ofstream out(filename.c_str());
- save_private(out);
-}
-
-/// Signs a statement with this private key.
-//
-/// @param statement The statement that is to be signed.
-/// @return A string containing the signature.
-string fides::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());
-}
-
-// Base64 and hex encoding/decoding functions
-
-/// Hexadecimal encode data.
-//
-/// @param in A string containing raw data.
-/// @return A string containing the hexadecimal encoded data.
-string fides::hexencode(const std::string &in) {
- Botan::Pipe pipe(new Botan::Hex_Encoder);
- pipe.process_msg((Botan::byte *)in.data(), in.size());
- return pipe.read_all_as_string();
-}
-
-/// Decode hexadecimal data.
-//
-/// @param in A string containing hexadecimal encoded data.
-/// @return A string containing the raw data.
-string fides::hexdecode(const std::string &in) {
- Botan::Pipe pipe(new Botan::Hex_Decoder);
- pipe.process_msg((Botan::byte *)in.data(), in.size());
- return pipe.read_all_as_string();
-}
-
-/// Base-64 encode data.
-//
-/// @param in A string containing raw data.
-/// @return A string containing the base-64 encoded data.
-string fides::b64encode(const std::string &in) {
- Botan::Pipe pipe(new Botan::Base64_Encoder);
- pipe.process_msg((Botan::byte *)in.data(), in.size());
- return pipe.read_all_as_string();
-}