Fix bug reported in #135

This commit is contained in:
Double Sine 2018-09-12 18:18:35 +08:00
parent 6459c56f25
commit a9d7f1004d
No known key found for this signature in database
GPG Key ID: 44460E4F43EA8633

View File

@ -114,10 +114,18 @@ int _tmain(int argc, TCHAR* argv[]) {
goto ON_tmain_ERROR;
}
} else {
_tprintf_s(TEXT("Generating new RSA private key, it may take long time.\n"));
do {
cipher->GenerateKey(2048);
} while (patcher::Solution0::CheckKey(cipher) && patcher::Solution1::CheckKey(cipher));
cipher->ExportKeyToFile<RSACipher::KeyType::PrivateKey, RSACipher::KeyFormat::PEM>("RegPrivateKey.pem");
} while (!patcher::Solution0::CheckKey(cipher) || !patcher::Solution1::CheckKey(cipher)); // re-generate RSA key if one of CheckKey return FALSE
if (!cipher->ExportKeyToFile<RSACipher::KeyType::PrivateKey, RSACipher::KeyFormat::NotSpecified>("RegPrivateKey.pem")) {
_tprintf_s(TEXT("@%s LINE: %u\n"), TEXT(__FUNCTION__), __LINE__);
_tprintf_s(TEXT("ERROR: Failed to save RSA private key.\n"));
goto ON_tmain_ERROR;
}
_tprintf_s(TEXT("New RSA private key has been saved to RegPrivateKey.pem.\n"));
}
@ -141,7 +149,9 @@ int _tmain(int argc, TCHAR* argv[]) {
if (!patcher::Solution0::Do(cipher))
goto ON_tmain_ERROR;
_tprintf_s(TEXT("RSA public key has been replaced by\n"));
printf_s("%s\n", cipher->ExportKeyString<RSACipher::KeyType::PublicKey, RSACipher::KeyFormat::PEM>().c_str());
_tprintf_s(TEXT("Solution0 has been done successfully.\n"));
_tprintf_s(TEXT("\n"));