Password prompt of --keyask now hides input
This commit is contained in:
parent
7e33d7ace7
commit
bbb6aaa574
@ -151,6 +151,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CommandlineInterface.h" />
|
||||
<ClInclude Include="Hazelnupp.h" />
|
||||
<ClInclude Include="Version.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -32,5 +32,8 @@
|
||||
<ClInclude Include="CommandlineInterface.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Version.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Binary file not shown.
@ -8,8 +8,51 @@
|
||||
#include "../GhettoCrypt/Flexblock.h"
|
||||
#include "../GhettoCrypt/Block.h"
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
#include <Windows.h>
|
||||
#elif defined __GNUG__
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace GhettoCipher;
|
||||
|
||||
//! Will prompt a user password from stdin, hiding the input
|
||||
std::string PasswordPrompt()
|
||||
{
|
||||
// Disable stdin-echo
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode(hStdin, &mode);
|
||||
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
|
||||
|
||||
#elif defined __GNUG__
|
||||
termios oldt;
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
termios newt = oldt;
|
||||
newt.c_lflag &= ~ECHO;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
|
||||
#endif
|
||||
|
||||
// Prompt stdin
|
||||
std::string key;
|
||||
std::cin >> key;
|
||||
|
||||
// Restore previous config
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
SetConsoleMode(hStdin, mode);
|
||||
|
||||
#elif defined __GNUG__
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
|
||||
#endif
|
||||
|
||||
// Return input
|
||||
return key;
|
||||
}
|
||||
|
||||
Block GetEncryptionKey()
|
||||
{
|
||||
// Easy-case: key supplied as param
|
||||
@ -18,11 +61,7 @@ Block GetEncryptionKey()
|
||||
|
||||
// Case: Ask for key
|
||||
else if (CommandlineInterface::Get().HasParam("--keyask"))
|
||||
{
|
||||
std::string key;
|
||||
std::cin >> key;
|
||||
return StringToBitblock(key);
|
||||
}
|
||||
return StringToBitblock(PasswordPrompt());
|
||||
|
||||
// Case: Read key from file
|
||||
else if (CommandlineInterface::Get().HasParam("--keyfile"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user