Add SHA-512 hash features

Fix also SHA-1 hash result wrong length bug while "Treat each line as a separate string" enabled.

Fix #13805, fix #13812, fix #13811, close #13806
This commit is contained in:
Don Ho 2023-06-20 03:10:34 +02:00
parent 32ce6b5b4c
commit 4ffd897ccf
16 changed files with 409 additions and 109 deletions

View File

@ -76,6 +76,7 @@ Translation note:
<Item subMenuId="tools-md5" name="MD5"/>
<Item subMenuId="tools-sha1" name="SHA-1"/>
<Item subMenuId="tools-sha256" name="SHA-256"/>
<Item subMenuId="tools-sha512" name="SHA-512"/>
<Item subMenuId="window-sortby" name="Sort By"/>
</SubEntries>
@ -545,6 +546,29 @@ Translation note:
<Item id="2" name="&amp;Close"/>
</SHA256FromTextDlg>
<SHA1FromFilesDlg title="Generate SHA-1 digest from files">
<Item id="1922" name="Choose files to &amp;generate SHA-1..."/>
<Item id="1924" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA1FromFilesDlg>
<SHA1FromTextDlg title="Generate SHA-1 digest">
<Item id="1932" name="Treat each line as a &amp;separate string"/>
<Item id="1934" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA1FromTextDlg>
<SHA512FromFilesDlg title="Generate SHA-512 digest from files">
<Item id="1922" name="Choose files to &amp;generate SHA-512..."/>
<Item id="1924" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA512FromFilesDlg>
<SHA512FromTextDlg title="Generate SHA-512 digest">
<Item id="1932" name="Treat each line as a &amp;separate string"/>
<Item id="1934" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA512FromTextDlg>
<PluginsAdminDlg title="Plugins Admin" titleAvailable="Available" titleUpdates="Updates" titleInstalled="Installed" titleIncompatible="Incompatible">
<ColumnPlugin name="Plugin"/>
<ColumnVersion name="Version"/>

View File

@ -76,6 +76,7 @@ Translation note:
<Item subMenuId="tools-md5" name="MD5"/>
<Item subMenuId="tools-sha1" name="SHA-1"/>
<Item subMenuId="tools-sha256" name="SHA-256"/>
<Item subMenuId="tools-sha512" name="SHA-512"/>
<Item subMenuId="window-sortby" name="Sort By"/>
</SubEntries>
@ -545,6 +546,30 @@ Translation note:
<Item id="2" name="&amp;Close"/>
</SHA256FromTextDlg>
<SHA1FromFilesDlg title="Generate SHA-1 digest from files">
<Item id="1922" name="Choose files to &amp;generate SHA-1..."/>
<Item id="1924" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA1FromFilesDlg>
<SHA1FromTextDlg title="Generate SHA-1 digest">
<Item id="1932" name="Treat each line as a &amp;separate string"/>
<Item id="1934" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA1FromTextDlg>
<SHA512FromFilesDlg title="Generate SHA-512 digest from files">
<Item id="1922" name="Choose files to &amp;generate SHA-512..."/>
<Item id="1924" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA512FromFilesDlg>
<SHA512FromTextDlg title="Generate SHA-512 digest">
<Item id="1932" name="Treat each line as a &amp;separate string"/>
<Item id="1934" name="Co&amp;py to Clipboard"/>
<Item id="2" name="&amp;Close"/>
</SHA512FromTextDlg>
<PluginsAdminDlg title="Plugins Admin" titleAvailable="Available" titleUpdates="Updates" titleInstalled="Installed" titleIncompatible="Incompatible">
<ColumnPlugin name="Plugin"/>
<ColumnVersion name="Version"/>

View File

@ -542,6 +542,30 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="1934" name="Copier dans le presse-papiers"/>
<Item id="2" name="Fermer"/>
</SHA256FromTextDlg>
<SHA1FromFilesDlg title="Calculer les empreintes de SHA-1 depuis les fichiers">
<Item id="1922" name="Choisir les fichiers pour générer les empreintes..."/>
<Item id="1924" name="Copier dans le presse-papiers"/>
<Item id="2" name="Fermer"/>
</SHA1FromFilesDlg>
<SHA1FromTextDlg title="Calculer l'empreinte de SHA-1">
<Item id="1932" name="Traiter chaque ligne comme une chaîne de caractères"/>
<Item id="1934" name="Copier dans le presse-papiers"/>
<Item id="2" name="Fermer"/>
</SHA1FromTextDlg>
<SHA512FromFilesDlg title="Calculer les empreintes de SHA-512 depuis les fichiers">
<Item id="1922" name="Choisir les fichiers pour générer les empreintes..."/>
<Item id="1924" name="Copier dans le presse-papiers"/>
<Item id="2" name="Fermer"/>
</SHA512FromFilesDlg>
<SHA512FromTextDlg title="Calculer l'empreinte de SHA-512">
<Item id="1932" name="Traiter chaque ligne comme une chaîne de caractères"/>
<Item id="1934" name="Copier dans le presse-papiers"/>
<Item id="2" name="Fermer"/>
</SHA512FromTextDlg>
<PluginsAdminDlg title="Gestionnaire des modules d'extension" titleAvailable="Disponibles" titleUpdates="Mises à jour" titleInstalled="Installés" titleIncompatible="Incompatibilité">
<ColumnPlugin name="Modules d'extension"/>

View File

@ -518,6 +518,30 @@
<Item id="1934" name="複製到剪貼簿"/>
<Item id="2" name="關閉"/>
</SHA256FromTextDlg>
<SHA1FromFilesDlg title="從檔案產生 SHA-1">
<Item id="1922" name="從檔案產生 SHA-1..."/>
<Item id="1924" name="複製到剪貼簿"/>
<Item id="2" name="關閉"/>
</SHA1FromFilesDlg>
<SHA1FromTextDlg title="產生 SHA-1">
<Item id="1932" name="將每一行視為獨立的字串"/>
<Item id="1934" name="複製到剪貼簿"/>
<Item id="2" name="關閉"/>
</SHA1FromTextDlg>
<SHA512FromFilesDlg title="從檔案產生 SHA-512">
<Item id="1922" name="從檔案產生 SHA-512..."/>
<Item id="1924" name="複製到剪貼簿"/>
<Item id="2" name="關閉"/>
</SHA512FromFilesDlg>
<SHA512FromTextDlg title="產生 SHA-512">
<Item id="1932" name="將每一行視為獨立的字串"/>
<Item id="1934" name="複製到剪貼簿"/>
<Item id="2" name="關閉"/>
</SHA512FromTextDlg>
<PluginsAdminDlg title="外掛模組管理" titleAvailable="可安裝" titleUpdates="更新" titleInstalled="已安裝" titleIncompatible="不相容">
<ColumnPlugin name="外掛模組"/>

View File

@ -17,6 +17,7 @@
#include "md5.h"
#include <stdint.h>
#include "sha-256.h"
#include "sha512.h"
#include "calc_sha1.h"
#include "md5Dlgs.h"
#include "md5Dlgs_rc.h"
@ -132,23 +133,35 @@ intptr_t CALLBACK HashFromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPA
{
std::string content = getFileContent(it.c_str());
bool isSha256 = (_ht == hashType::hash_sha256);
uint8_t hash[HASH_MAX_LENGTH]{};
wchar_t hashStr[HASH_STR_MAX_LENGTH]{};
uint8_t hash[32]{}; // align to the longest hash (SHA-256)
wchar_t hashStr[65]{}; // align to the longest hash (SHA-256)
size_t hashLen = 0;
if (isSha256)
switch (_ht)
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
hashLen = 32;
}
else
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
hashLen = 20;
case hash_sha1:
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
}
break;
case hash_sha256:
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
}
break;
case hash_sha512:
{
calc_sha_512(hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
}
break;
default:
return FALSE;
}
for (size_t i = 0; i < hashLen; i++)
for (int i = 0; i < _ht; i++)
wsprintf(hashStr + i * 2, TEXT("%02x"), hash[i]);
files2check += it;
@ -227,23 +240,37 @@ void HashFromFilesDlg::doDialog(bool isRTL)
if (!isCreated())
{
create(IDD_HASHFROMFILES_DLG, isRTL);
std::wstring title;
std::wstring buttonText;
if (_ht == hash_sha256)
switch (_ht)
{
generic_string title = TEXT("Generate SHA-256 digest from files");
::SetWindowText(_hSelf, title.c_str());
case hash_sha1:
{
title = TEXT("Generate SHA-1 digest from files");
buttonText = TEXT("Choose files to &generate SHA-1...");
}
break;
generic_string buttonText = TEXT("Choose files to &generate SHA-256...");
::SetDlgItemText(_hSelf, IDC_HASH_FILEBROWSER_BUTTON, buttonText.c_str());
}
else if (_ht == hash_sha1)
{
generic_string title = TEXT("Generate SHA-1 digest from files");
::SetWindowText(_hSelf, title.c_str());
case hash_sha256:
{
title = TEXT("Generate SHA-256 digest from files");
buttonText = TEXT("Choose files to &generate SHA-256...");
}
break;
generic_string buttonText = TEXT("Choose files to &generate SHA-1...");
::SetDlgItemText(_hSelf, IDC_HASH_FILEBROWSER_BUTTON, buttonText.c_str());
case hash_sha512:
{
title = TEXT("Generate SHA-1 digest from files");
buttonText = TEXT("Choose files to &generate SHA-512...");
}
break;
default:
return;
}
::SetWindowText(_hSelf, title.c_str());
::SetDlgItemText(_hSelf, IDC_HASH_FILEBROWSER_BUTTON, buttonText.c_str());
}
// Adjust the position in the center
@ -252,7 +279,7 @@ void HashFromFilesDlg::doDialog(bool isRTL)
void HashFromTextDlg::generateHash()
{
if (_ht != hash_md5 && _ht != hash_sha256 && _ht != hash_sha1)
if (_ht != hash_md5 && _ht != hash_sha1 && _ht != hash_sha256 && _ht != hash_sha512)
return;
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_TEXT_EDIT), WM_GETTEXTLENGTH, 0, 0));
@ -272,23 +299,34 @@ void HashFromTextDlg::generateHash()
}
else
{
uint8_t hash[32]{}; // align to the longest hash (SHA-256)
wchar_t hashStr[65]{}; // align to the longest hash (SHA-256)
size_t hashLen = 0;
bool isSha256 = (_ht == hash_sha256);
uint8_t hash[HASH_MAX_LENGTH]{};
wchar_t hashStr[HASH_STR_MAX_LENGTH]{};
if (isSha256)
switch (_ht)
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
hashLen = 32;
}
else
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
hashLen = 20;
case hash_sha1:
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
case hash_sha256:
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
case hash_sha512:
{
calc_sha_512(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
default:
return;
}
for (size_t i = 0; i < hashLen; i++)
for (int i = 0; i < _ht; i++)
wsprintf(hashStr + i * 2, TEXT("%02x"), hash[i]);
::SetDlgItemText(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, hashStr);
@ -312,54 +350,78 @@ void HashFromTextDlg::generateHashPerLine()
std::wstringstream ss(text);
std::wstring aLine;
std::string result;
MD5 md5;
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
while (std::getline(ss, aLine))
{
// getline() detect only '\n' but not "\r\n" under windows
// this hack is to walk around such bug
if (aLine.back() == '\r')
aLine = aLine.substr(0, aLine.size() - 1);
if (aLine.empty())
if (aLine.empty()) // in case of UNIX EOL
{
result += "\r\n";
}
else
{
const char *newText = wmc.wchar2char(aLine.c_str(), SC_CP_UTF8);
// getline() detect only '\n' but not "\r\n" under Windows
// this hack is to walk around such bug
if (aLine.back() == '\r')
aLine = aLine.substr(0, aLine.size() - 1);
if (_ht == hash_md5)
if (aLine.empty()) // Windows EOL, both \n & \r are removed
{
char* md5Result = md5.digestString(newText);
result += md5Result;
result += "\r\n";
}
else
{
uint8_t hash[32]{}; // align to the longest hash (SHA-256)
char hashStr[65]{}; // align to the longest hash (SHA-256)
size_t hashLen = 0;
bool isSha256 = (_ht == hash_sha256);
const char* newText = wmc.wchar2char(aLine.c_str(), SC_CP_UTF8);
if (isSha256)
if (_ht == hash_md5)
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
hashLen = 32;
MD5 md5;
char* md5Result = md5.digestString(newText);
result += md5Result;
result += "\r\n";
}
else
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
hashLen = 20;
}
for (size_t i = 0; i < 32; i++)
sprintf(hashStr + i * 2, "%02x", hash[i]);
uint8_t hash[HASH_MAX_LENGTH]{};
char hashStr[HASH_STR_MAX_LENGTH]{};
result += hashStr;
result += "\r\n";
switch (_ht)
{
case hash_sha1:
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
case hash_sha256:
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
case hash_sha512:
{
calc_sha_512(hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
}
break;
default:
return;
}
for (int i = 0; i < _ht; i++)
sprintf(hashStr + i * 2, "%02x", hash[i]);
result += hashStr;
result += "\r\n";
}
}
}
}
delete[] text;
::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, result.c_str());
}
else
@ -501,17 +563,32 @@ void HashFromTextDlg::doDialog(bool isRTL)
if (!isCreated())
{
create(IDD_HASHFROMTEXT_DLG, isRTL);
std::wstring title;
switch (_ht)
{
case hash_sha1:
{
title = TEXT("Generate SHA-1 digest");
}
break;
if (_ht == hash_sha256)
{
generic_string title = TEXT("Generate SHA-256 digest");
::SetWindowText(_hSelf, title.c_str());
}
else if (_ht == hash_sha1)
{
generic_string title = TEXT("Generate SHA-1 digest");
::SetWindowText(_hSelf, title.c_str());
case hash_sha256:
{
title = TEXT("Generate SHA-256 digest");
}
break;
case hash_sha512:
{
title = TEXT("Generate SHA-512 digest");
}
break;
default:
break;
}
::SetWindowText(_hSelf, title.c_str());
}
// Adjust the position in the center

View File

@ -18,7 +18,10 @@
#include "StaticDialog.h"
enum hashType {hash_md5, hash_sha256, hash_sha1};
enum hashType {hash_md5 = 16, hash_sha1 = 20, hash_sha256 = 32, hash_sha512 = 64};
#define HASH_MAX_LENGTH hash_sha512
#define HASH_STR_MAX_LENGTH (hash_sha512 * 2 + 1)
LRESULT run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -0,0 +1,56 @@
// This file is part of Notepad++ project
// Copyright (C)2023 Don HO <don.h@free.fr>
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Windows.h>
#include <wincrypt.h>
#include "sha512.h"
#pragma comment(lib, "crypt32.lib")
void calc_sha_512(unsigned char hash[64], const void *input, size_t len) {
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
DWORD dwHashLen = 64;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
//std::cerr << "CryptAcquireContext failed: " << GetLastError() << std::endl;
return;
}
if (!CryptCreateHash(hProv, CALG_SHA_512, 0, 0, &hHash)) {
//std::cerr << "CryptCreateHash failed: " << GetLastError() << std::endl;
CryptReleaseContext(hProv, 0);
return;
}
if (!CryptHashData(hHash, (BYTE*)input, DWORD(len), 0)) {
//std::cerr << "CryptHashData failed: " << GetLastError() << std::endl;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
return;
}
if (!CryptGetHashParam(hHash, HP_HASHVAL, hash, &dwHashLen, 0)) {
//std::cerr << "CryptGetHashParam failed: " << GetLastError() << std::endl;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
return;
}
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
}

View File

@ -0,0 +1,19 @@
// This file is part of Notepad++ project
// Copyright (C)2023 Don HO <don.h@free.fr>
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
void calc_sha_512(unsigned char hash[64], const void *input, size_t len);

View File

@ -717,6 +717,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
_sha1FromFilesDlg.setHashType(hash_sha1);
_sha1FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
_sha1FromTextDlg.setHashType(hash_sha1);
_sha512FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd);
_sha512FromFilesDlg.setHashType(hash_sha512);
_sha512FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
_sha512FromTextDlg.setHashType(hash_sha512);
//--User Define Dialog Section--//

View File

@ -316,6 +316,8 @@ private:
HashFromTextDlg _sha2FromTextDlg;
HashFromFilesDlg _sha1FromFilesDlg;
HashFromTextDlg _sha1FromTextDlg;
HashFromFilesDlg _sha512FromFilesDlg;
HashFromTextDlg _sha512FromTextDlg;
GoToLineDlg _goToLineDlg;
ColumnEditorDlg _colEditorDlg;
WordStyleDlg _configStyleDlg;

View File

@ -1185,6 +1185,12 @@ BEGIN
MENUITEM "Generate from files...", IDM_TOOL_SHA256_GENERATEFROMFILE
MENUITEM "Generate from selection into clipboard", IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD
END
POPUP "SHA-512"
BEGIN
MENUITEM "Generate...", IDM_TOOL_SHA512_GENERATE
MENUITEM "Generate from files...", IDM_TOOL_SHA512_GENERATEFROMFILE
MENUITEM "Generate from selection into clipboard", IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD
END
END
POPUP "&Macro"

View File

@ -34,6 +34,7 @@
#include "md5.h"
#include "sha-256.h"
#include "calc_sha1.h"
#include "sha512.h"
using namespace std;
@ -3214,24 +3215,6 @@ void Notepad_plus::command(int id)
}
break;
case IDM_TOOL_SHA256_GENERATE:
{
bool isFirstTime = !_sha2FromTextDlg.isCreated();
_sha2FromTextDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromTextDlg.getHSelf(), "SHA256FromTextDlg");
}
break;
case IDM_TOOL_SHA256_GENERATEFROMFILE:
{
bool isFirstTime = !_sha2FromFilesDlg.isCreated();
_sha2FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromFilesDlg.getHSelf(), "SHA256FromFilesDlg");
}
break;
case IDM_TOOL_SHA1_GENERATE:
{
bool isFirstTime = !_sha1FromTextDlg.isCreated();
@ -3250,8 +3233,45 @@ void Notepad_plus::command(int id)
}
break;
case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD:
case IDM_TOOL_SHA256_GENERATE:
{
bool isFirstTime = !_sha2FromTextDlg.isCreated();
_sha2FromTextDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromTextDlg.getHSelf(), "SHA256FromTextDlg");
}
break;
case IDM_TOOL_SHA256_GENERATEFROMFILE:
{
bool isFirstTime = !_sha2FromFilesDlg.isCreated();
_sha2FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromFilesDlg.getHSelf(), "SHA256FromFilesDlg");
}
break;
case IDM_TOOL_SHA512_GENERATE:
{
bool isFirstTime = !_sha512FromTextDlg.isCreated();
_sha512FromTextDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha512FromTextDlg.getHSelf(), "SHA512FromTextDlg");
}
break;
case IDM_TOOL_SHA512_GENERATEFROMFILE:
{
bool isFirstTime = !_sha512FromFilesDlg.isCreated();
_sha512FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha512FromFilesDlg.getHSelf(), "SHA512FromFilesDlg");
}
break;
case IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD:
case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD:
case IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD:
{
if (_pEditView->execute(SCI_GETSELECTIONS) == 1)
{
@ -3265,23 +3285,33 @@ void Notepad_plus::command(int id)
char *selectedStr = new char[strSize];
_pEditView->execute(SCI_GETSELTEXT, 0, reinterpret_cast<LPARAM>(selectedStr));
bool isSha256 = (id == IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD);
uint8_t hash[HASH_MAX_LENGTH] {};
wchar_t hashStr[HASH_STR_MAX_LENGTH] {};
uint8_t hash[32] {}; // align to the longest hash (SHA-256)
wchar_t hashStr[65] {}; // align to the longest hash (SHA-256)
size_t hashLen = 0;
if (isSha256)
switch (id)
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
hashLen = 32;
case IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD:
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
}
break;
case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD:
{
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
}
break;
case IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD:
{
calc_sha_512(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
}
break;
default:
return;
}
else // SHA1
{
calc_sha1(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
hashLen = 20;
}
for (size_t i = 0; i < hashLen; i++)
for (int i = 0; i < id; i++)
wsprintf(hashStr + i * 2, TEXT("%02x"), hash[i]);
str2Clipboard(hashStr, _pPublicInterface->getHSelf());

View File

@ -100,6 +100,7 @@ MenuPosition menuPos[] = {
{ 7, 0, -1, "tools-md5" },
{ 7, 1, -1, "tools-sha1" },
{ 7, 2, -1, "tools-sha256" },
{ 7, 3, -1, "tools-sha512" },
{ 11, 0, -1, "window-sortby"},

View File

@ -596,6 +596,9 @@
#define IDM_TOOL_SHA1_GENERATE (IDM_TOOL + 7)
#define IDM_TOOL_SHA1_GENERATEFROMFILE (IDM_TOOL + 8)
#define IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD (IDM_TOOL + 9)
#define IDM_TOOL_SHA512_GENERATE (IDM_TOOL + 10)
#define IDM_TOOL_SHA512_GENERATEFROMFILE (IDM_TOOL + 11)
#define IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD (IDM_TOOL + 12)
#define IDM_EXECUTE (IDM + 9000)

View File

@ -24,7 +24,7 @@
</PropertyGroup>
<ItemDefinitionGroup Label="Globals">
<ClCompile>
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\sha512;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_VISTA;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<WarningLevel>Level4</WarningLevel>

View File

@ -112,6 +112,7 @@
<ClCompile Include="..\src\MISC\sha1\calc_sha1.cpp" />
<ClCompile Include="..\src\MISC\sha1\sha1.cpp" />
<ClCompile Include="..\src\MISC\sha2\sha-256.cpp" />
<ClCompile Include="..\src\MISC\sha512\sha512.cpp" />
<ClCompile Include="..\src\NppDarkMode.cpp" />
<ClCompile Include="..\src\WinControls\AboutDlg\AboutDlg.cpp" />
<ClCompile Include="..\src\WinControls\AnsiCharPanel\ansiCharPanel.cpp" />
@ -251,6 +252,7 @@
<ClInclude Include="..\src\MISC\sha1\calc_sha1.h" />
<ClInclude Include="..\src\MISC\sha1\sha1.h" />
<ClInclude Include="..\src\MISC\sha2\sha-256.h" />
<ClInclude Include="..\src\MISC\sha512\sha512.h" />
<ClInclude Include="..\src\NppDarkMode.h" />
<ClInclude Include="..\src\ScintillaComponent\columnEditor_rc.h" />
<ClInclude Include="..\src\ScintillaComponent\FindReplaceDlg_rc.h" />