split key generation and key writing
This commit is contained in:
@@ -188,7 +188,7 @@ CryptManager::CryptManager()
|
|||||||
if( bGenerate )
|
if( bGenerate )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Keys missing or failed to load. Generating new keys" );
|
LOG->Warn( "Keys missing or failed to load. Generating new keys" );
|
||||||
GenerateRSAKey( KEY_LENGTH, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH );
|
GenerateRSAKeyToFile( KEY_LENGTH, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH );
|
||||||
FlushDirCache();
|
FlushDirCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ static bool WriteFile( RString sFile, RString sBuf )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryptManager::GenerateRSAKey( unsigned int keyLength, RString privFilename, RString pubFilename )
|
void CryptManager::GenerateRSAKey( unsigned int keyLength, RString &sPrivKey, RString &sPubKey )
|
||||||
{
|
{
|
||||||
int iRet;
|
int iRet;
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ void CryptManager::GenerateRSAKey( unsigned int keyLength, RString privFilename,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RString sPubKey( (const char *) buf, iSize );
|
sPubKey = RString( (const char *) buf, iSize );
|
||||||
|
|
||||||
iSize = sizeof(buf);
|
iSize = sizeof(buf);
|
||||||
iRet = rsa_export( buf, &iSize, PK_PRIVATE, &key );
|
iRet = rsa_export( buf, &iSize, PK_PRIVATE, &key );
|
||||||
@@ -249,7 +249,13 @@ void CryptManager::GenerateRSAKey( unsigned int keyLength, RString privFilename,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RString sPrivKey( (const char *) buf, iSize );
|
sPrivKey = RString( (const char *) buf, iSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CryptManager::GenerateRSAKeyToFile( unsigned int keyLength, RString privFilename, RString pubFilename )
|
||||||
|
{
|
||||||
|
RString sPrivKey, sPubKey;
|
||||||
|
GenerateRSAKey( keyLength, sPrivKey, sPubKey );
|
||||||
|
|
||||||
if( !WriteFile(pubFilename, sPubKey) )
|
if( !WriteFile(pubFilename, sPubKey) )
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ public:
|
|||||||
CryptManager();
|
CryptManager();
|
||||||
~CryptManager();
|
~CryptManager();
|
||||||
|
|
||||||
static void GenerateRSAKey( unsigned int keyLength, RString privFilename, RString pubFilename );
|
static void GenerateRSAKey( unsigned int keyLength, RString &sPrivKey, RString &sPubKey );
|
||||||
|
static void GenerateRSAKeyToFile( unsigned int keyLength, RString privFilename, RString pubFilename );
|
||||||
static void SignFileToFile( RString sPath, RString sSignatureFile = "" );
|
static void SignFileToFile( RString sPath, RString sSignatureFile = "" );
|
||||||
static bool Sign( RString sPath, RString &sSignatureOut, RString sPrivateKey );
|
static bool Sign( RString sPath, RString &sSignatureOut, RString sPrivateKey );
|
||||||
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
static bool VerifyFileWithFile( RString sPath, RString sSignatureFile = "" );
|
||||||
|
|||||||
Reference in New Issue
Block a user