/* * CERT_LicenseVerifier.h * * Created by Andrew Salamon on 9/15/08. * Copyright 2008 Machine Perception Laboratory, University of California San Diego. All rights reserved. * */ #ifndef __CERT_LICENSEVERIFIER_H__ #define __CERT_LICENSEVERIFIER_H__ #include #include #include #include namespace CERT { namespace Licensing { class keyException : public std::runtime_error { public: keyException( const std::string &msg ) : std::runtime_error(msg) { } }; class encryptionException : public std::runtime_error { public: encryptionException( const std::string &msg ) : std::runtime_error(msg) { } }; class decryptionException : public encryptionException { public: decryptionException( const std::string &msg ) : encryptionException(msg) { } }; } class LicenseVerifier { public: static std::string encodeBase64( const std::string &str ); static std::string decodeBase64( const std::string &str ); public: LicenseVerifier(); LicenseVerifier( const std::string &privateKeyPath ); std::string encrypt( const std::string &plaintext ); ///< Will throw an exception if a private key hasn't been loaded. std::string decrypt( const std::string &cyphertext ); bool loadPrivateKey( const std::string &privateKeyPath ); private: RSA *privateKey; RSA *publicKey; void setPrivateKey( RSA *key ); void setPublicKey( RSA *key ); bool loadPublicKey( const std::string &keyString ); }; } // end namespace CERT #endif