193 if (
nullptr != m_pkeyPublic)
delete m_pkeyPublic;
194 m_pkeyPublic =
nullptr;
196 if (
nullptr != m_pkeyPrivate)
delete m_pkeyPrivate;
197 m_pkeyPrivate =
nullptr;
233 return (*m_pkeyPublic);
240 return (*m_pkeyPrivate);
250 strReason(
nullptr == pstrReason ?
"OTKeypair::SaveCertToString"
251 : pstrReason->
Get());
256 if (bSaved) strOutput = strCert;
270 strPrivateKey, pstrReason, pImportPassword);
272 if (bSaved) strOutput = strPrivateKey;
283 const bool bSaved1 =
SaveCertToString(strCert, pstrReason, pImportPassword);
287 if (bSaved1 && bSaved2)
288 strOutput.
Format(const_cast<char*>(
"%s%s"), strPrivateKey.
Get(),
291 return (bSaved1 && bSaved2);
304 pstrReason, pImportPassword);
307 pstrReason, pImportPassword);
309 otErr << __FUNCTION__
310 <<
": Although the input string apparently exists, "
311 "LoadPublicKeyFromCertString returned false.\n";
316 <<
": Successfully loaded public key from string.\n";
320 otErr << __FUNCTION__
321 <<
": Although the input string apparently exists, "
322 "LoadPrivateKeyFromCertString returned false.\n";
327 <<
": Successfully loaded private key from string.\n";
341 const bool bSuccess =
347 const OTString strFilename(
"temp.nym");
354 otErr << __FUNCTION__
355 <<
": Failure storing new cert in temp file: " << strFilename
361 pstrReason, pImportPassword))
365 if (
nullptr != pstrOutputCert)
366 pstrOutputCert->
Set(strOutput);
380 return m_pkeyPrivate->
LoadPrivateKey(strFoldername, strFilename, pstrReason,
389 return m_pkeyPublic->
LoadPublicKey(strFoldername, strFilename);
404 strCert, bEscaped, pstrReason, pImportPassword);
416 strCert, bEscaped, pstrReason, pImportPassword);
427 pstrReason, pImportPassword);
438 otErr <<
"OTKeypair::MakeNewKeypair"
439 <<
": Failed in a call to OTLowLevelKeyData::MakeNewKeypair("
461 const char* szFunc =
"OTKeypair::LoadBothKeysFromCertFile";
467 strFoldername.
Get(), strFilename.
Get(), pstrReason, pImportPassword);
469 strFoldername.
Get(), strFilename.
Get(), pstrReason, pImportPassword);
471 otErr << szFunc <<
": Although the ascii-armored file (" << strFilename
472 <<
") was read, LoadPublicKeyFromCert "
477 otInfo << szFunc <<
": Successfully loaded public key from Certfile: "
478 << strFilename <<
"\n";
482 otErr << szFunc <<
": Although the ascii-armored file (" << strFilename
483 <<
") was read, LoadPrivateKey returned false.\n";
487 otInfo << szFunc <<
": Successfully loaded private key from certfile: "
488 << strFilename <<
"\n";
499 return theContract.
SignWithKey(*m_pkeyPrivate, pPWData);
542 if (strKey.
Contains(
"PGP PUBLIC KEY")) {
545 if (theArmor.
LoadFromString(const_cast<OTString&>(strKey), bEscaped)) {
552 otInfo <<
"OTKeypair::SetPublicKey: Failed extracting PGP public "
553 "key from ascii-armored text.\n";
581 return m_pkeyPrivate->GetPrivateKey(strKey);
592 const char* szOverride =
"PGP PRIVATE KEY";
597 if (theArmor.
LoadFromString(const_cast<OTString&>(strKey), bEscaped,
607 otOut <<
"OTKeypair::SetPrivateKey 1: Failure: PGP private keys "
608 "are NOT YET SUPPORTED.\n\n";
615 otOut <<
"OTKeypair::SetPrivateKey 2: Failure: PGP private keys "
616 "are NOT YET SUPPORTED.\n\n";
653 const OTSignature& theSignature,
bool bInclusive)
const
665 if ((
false == bInclusive) &&
684 listOutput.push_back(m_pkeyPublic);
713 bImporting ?
"Enter the new export passphrase. (Above "
714 "ReEncryptPrivateKey in OTKeypair::ReEncrypt)"
715 :
"Enter your wallet's master passphrase. (Above "
716 "ReEncryptPrivateKey in OTKeypair::ReEncrypt)");
719 bImporting ?
"Enter your wallet's master passphrase. (Below "
720 "ReEncryptPrivateKey in OTKeypair::ReEncrypt)"
721 :
"Enter the new export passphrase. (Below "
722 "ReEncryptPrivateKey in OTKeypair::ReEncrypt)");
748 theExportPassword, bImporting);
749 bool bGotCert =
false;
755 &strOutput, &strReasonBelow,
756 bImporting ?
nullptr : &theExportPassword);
759 const bool bSuccess = (bReEncrypted && bGotCert);
763 otErr << __FUNCTION__ <<
": Failure, either when re-encrypting, or "
764 "when subsequently retrieving "
765 "the public/private keys. bImporting == "
766 << (bImporting ?
"true" :
"false") <<
"\n";
EXPORT bool LoadCertAndPrivateKeyFromString(const OTString &strInput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool ReEncrypt(const OTPassword &theExportPassword, bool bImporting, OTString &strOutput)
bool MakeNewKeypair(int32_t nBits=1024)
virtual bool ReEncryptPrivateKey(const OTPassword &theExportPassword, bool bImporting) const =0
std::list< OTAsymmetricKey * > listOfAsymmetricKeys
EXPORT const OTAsymmetricKey & GetPublicKey() const
virtual bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
EXPORT int32_t GetPublicKeyBySignature(listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, bool bInclusive=false) const
bool LoadPublicKey(const OTString &strFoldername, const OTString &strFilename)
EXPORT bool SavePrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool SaveAndReloadBothKeysFromTempFile(OTString *pstrOutputCert=nullptr, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
OTSignatureMetadata * m_pMetadata
EXPORT bool LoadBothKeysFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
OTLOG_IMPORT OTLogStream otOut
EXPORT bool HasPublicKey()
EXPORT void SetMetadata(const OTSignatureMetadata &theMetadata)
virtual bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
bool LoadPublicKeyFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
virtual bool SaveCertToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
EXPORT bool Exists() const
bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
EXPORT bool SignWithKey(const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr)
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
EXPORT void Format(const char *fmt,...)
virtual bool LoadPublicKeyFromPGPKey(const OTASCIIArmor &strKey)=0
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
bool GetPrivateKey(OTString &strKey, bool bEscaped=true) const
EXPORT bool CalculateID(OTIdentifier &theOutput) const
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
virtual bool SavePrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
virtual bool CalculateID(OTIdentifier &theOutput) const
OTSignatureMetadata & getMetaData()
OTLOG_IMPORT OTLogStream otInfo
EXPORT bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT const OTAsymmetricKey & GetPrivateKey() const
EXPORT bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
bool LoadPrivateKey(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT const char * Get() const
OTLOG_IMPORT OTLogStream otErr
EXPORT bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
EXPORT bool SaveCertToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool HasPrivateKey()
EXPORT bool SaveCertAndPrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
bool SetOntoKeypair(OTKeypair &theKeypair)
EXPORT bool LoadPublicKey(const OTString &strFoldername, const OTString &strFilename)
EXPORT bool Contains(const char *compare) const
static EXPORT const OTString & Cert()
EXPORT bool LoadPrivateKey(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT bool MakeNewKeypair(int32_t nBits=1024)
EXPORT bool SignContract(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
virtual EXPORT void Release()
EXPORT bool LoadPublicKeyFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)