예제 #1
0
void save_pair(const std::string& name,
               const std::string& password,
               const X509_Certificate& cert,
               const Private_Key& key,
               RandomNumberGenerator& rng)
{
    std::string cert_fsname = name + "_cert.pem";
    std::string key_fsname = name + "_key.pem";

    std::ofstream cert_out(cert_fsname.c_str());
    cert_out << cert.PEM_encode() << "\n";
    cert_out.close();

    std::ofstream key_out(key_fsname.c_str());
    if(password != "")
        key_out << PKCS8::PEM_encode(key, rng, password);
    else
        key_out << PKCS8::PEM_encode(key);
    key_out.close();
}