KeePass
应用介绍
KeePass Password Safe是一个免费,开源,轻便且易于使用的密码管理器,适用于Windows,Linux和Mac OS X,带有适用于Android,iPhone / iPad和其他移动设备的端口。 记住了这么多的密码,并且需要更改密码来保护您的宝贵数据,因此KeePass可以安全地管理您的密码,这是很好的选择。 KeePass将所有密码放入一个高度加密的数据库中,并使用一个主密钥或一个密钥文件将其锁定。 因此,您只需要记住一个主密码或选择密钥文件即可解锁整个数据库。 并且使用目前已知的最佳和最安全的加密算法AES和Twofish对数据库进行加密。 有关详细信息,请参见我们的功能页面。
特征
强大的安全性(AES加密,SHA-256哈希,针对字典和猜测攻击的保护,内存中的保护,...)。
便携式(无需安装),可用于许多平台(Windows,Linux,Mac OS X,智能设备/电话等)。
高效灵活的组织(条目组,标签,时间字段,文件附件等)。
各种数据传输方法(剪贴板,拖放,自动键入,插件可以提供与其他应用程序的集成,...)。
强大的密码生成器(根据字符集和模式生成,具有许多选项)。
可扩展(插件体系结构)和多语言(可用40多种语言)。
源代码已经在vs2010测试通过, 带gui界面, MFC编写 ,学习其中源代码,对编程提升很大, 不少加密算法可以拿来直接用。下面列出了生成密码代码。
#include "StdAfx.h"
#include "PasswordGenerator.h"
#include "CharSetBasedGenerator.h"
#include "PatternBasedGenerator.h"
#include <algorithm>
#include <boost/scoped_array.hpp>
#include "../Util/Base64.h"
#include "../Util/PwUtil.h"
#include "../Util/StrUtil.h"
#include "../Util/MemUtil.h"
using boost::scoped_array;
PWG_ERROR PwgGenerateEx(std::vector<TCHAR>& vOutPassword,
const PW_GEN_SETTINGS_EX* pSettings, CNewRandom* pRandomSource)
{
ASSERT(pSettings != NULL);
if(pSettings == NULL) return PWGE_NULL_PTR;
EraseTCharVector(vOutPassword);
CNewRandom* pAllocatedRandom = NULL;
CNewRandom* pRandom = pRandomSource;
if(pRandom == NULL)
{
pAllocatedRandom = new CNewRandom();
pRandom = pAllocatedRandom;
}
std::vector<WCHAR> vOutBuffer;
PWG_ERROR pwgErr = PWGE_UNKNOWN_GENERATOR;
if(pSettings->btGeneratorType == PWGT_CHARSET)
pwgErr = CsbgGenerate(vOutBuffer, pSettings, pRandom);
else if(pSettings->btGeneratorType == PWGT_PATTERN)
{
// Fill output buffer with dummy password
PbgGenerate(vOutBuffer, pSettings, pRandom);
// Now generate the real password (this will overwrite
// the characters in the buffer and won't do any memory
// relocations, i.e. the final characters will be in
// this place only and can be erased securely later)
pwgErr = PbgGenerate(vOutBuffer, pSettings, pRandom);
}
if((vOutBuffer.size() == 0) || (std::find(vOutBuffer.begin(),
vOutBuffer.end(), 0) == vOutBuffer.end()))
{
vOutBuffer.push_back(0); // Terminate string
vOutBuffer.push_back(0);
}
#ifdef _UNICODE
vOutPassword.resize(vOutBuffer.size());
for(size_t dwCopy = 0; dwCopy < vOutBuffer.size(); ++dwCopy)
vOutPassword[dwCopy] = vOutBuffer[dwCopy];
#else
char *pFinalString = _StringToAnsi(&vOutBuffer[0]);
vOutPassword.resize(szlen(pFinalString) + 1);
for(DWORD dwCopy = 0; dwCopy <= szlen(pFinalString); ++dwCopy)
vOutPassword[dwCopy] = pFinalString[dwCopy];
mem_erase((unsigned char *)pFinalString, szlen(pFinalString));
SAFE_DELETE_ARRAY(pFinalString);
#endif
EraseWCharVector(vOutBuffer);
SAFE_DELETE(pAllocatedRandom);
return pwgErr;
}
WCHAR PwgGenerateCharacter(const PW_GEN_SETTINGS_EX* pSettings,
CNewRandom* pRandom, PwCharSet* pCharSet)
{
ASSERT(pSettings != NULL); if(pSettings == NULL) return 0;
ASSERT(pRandom != NULL); if(pRandom == NULL) return 0;
ASSERT(pCharSet != NULL); if(pCharSet == NULL) return 0;
if(pCharSet->Size() == 0) return 0;
ASSERT(sizeof(UINT64) == 8);
UINT64 uIndex;
pRandom->GetRandomBuffer((BYTE *)&uIndex, sizeof(UINT64));
uIndex %= static_cast<UINT64>(pCharSet->Size());
const WCHAR wch = pCharSet->GetAt(static_cast<unsigned int>(uIndex));
if(pSettings->bNoRepeat != FALSE) pCharSet->Remove(wch);
return wch;
}
void PwgPrepareCharSet(PwCharSet* pCharSet, const PW_GEN_SETTINGS_EX* pSettings)
{
ASSERT(pCharSet != NULL); if(pCharSet == NULL) return;
ASSERT(pSettings != NULL); if(pSettings == NULL) return;
pCharSet->Remove(PDCS_INVALID);
if(pSettings->bNoConfusing != FALSE)
pCharSet->Remove(PDCS_CONFUSING);
if(pSettings->strExcludeChars.size() > 0)
pCharSet->Remove(pSettings->strExcludeChars.c_str());
}
void PwgShufflePassword(std::vector<WCHAR>& vBuffer, CNewRandom* pRandom)
{
ASSERT(pRandom != NULL); if(pRandom == NULL) return;
DWORD dwLength = static_cast<DWORD>(vBuffer.size());
// Update length by finding the first 0 character
for(DWORD dwScan = 0; dwScan < vBuffer.size(); ++dwScan)
{
if(vBuffer[dwScan] == 0)
{
dwLength = dwScan;
break;
}
}
if(dwLength <= 1) return; // Nothing to permute
ASSERT(sizeof(UINT64) == 8);
UINT64 uRandomIndex;
for(DWORD dwSelect = 0; dwSelect < (dwLength - 1); ++dwSelect)
{
pRandom->GetRandomBuffer((BYTE *)&uRandomIndex, sizeof(UINT64));
uRandomIndex %= (UINT64)(dwLength - dwSelect);
ASSERT((dwSelect + (DWORD)uRandomIndex) < dwLength);
WCHAR wchTemp = vBuffer[dwSelect];
vBuffer[dwSelect] = vBuffer[dwSelect + (DWORD)uRandomIndex];
vBuffer[dwSelect + (DWORD)uRandomIndex] = wchTemp;
}
ASSERT(wcslen(&vBuffer[0]) == dwLength);
}
LPCTSTR PwgErrorToString(PWG_ERROR uError)
{
if(uError == PWGE_SUCCESS) return _T("Success");
if(uError == PWGE_NULL_PTR) return _T("Internal error");
if(uError == PWGE_UNKNOWN_GENERATOR) return _T("Internal error");
if(uError == PWGE_TOO_FEW_CHARACTERS)
return _T("There are too few characters in the character set to build up a password matching the specified rules");
return _T("Unknown error");
}
/* std::basic_string<WCHAR> HexStrToWCharStr(LPCTSTR lpString)
{
std::basic_string<WCHAR> str;
ASSERT(lpString != NULL); if(lpString == NULL) return str;
DWORD dwLength = _tcslen(lpString), i = 0;
if((dwLength & 3) != 0) { ASSERT(FALSE); return str; }
BYTE bt1, bt2;
while(true)
{
TCHAR ch1 = lpString[i], ch2 = lpString[i + 1];
TCHAR ch3 = lpString[i + 2], ch4 = lpString[i + 3];
ConvertStrToHex(ch1, ch2, bt1);
ConvertStrToHex(ch3, ch4, bt2);
str += (WCHAR)((((WCHAR)bt1) << 8) | ((WCHAR)bt2));
i += 4;
if(lpString[i] == 0) break;
}
return str;
}
std::basic_string<TCHAR> WCharVecToHexStr(const std::vector<WCHAR>& vec)
{
std::basic_string<TCHAR> strOut;
TCHAR ch1, ch2;
for(DWORD i = 0; i < vec.size(); ++i)
{
ConvertHexToStr((BYTE)(vec[i] >> 8), ch1, ch2);
strOut += ch1;
strOut += ch2;
ConvertHexToStr((BYTE)(vec[i] & 0xFF), ch1, ch2);
strOut += ch1;
strOut += ch2;
}
return strOut;
} */
std::basic_string<TCHAR> PwgProfileToString(const PW_GEN_SETTINGS_EX* pSettings)
{
std::basic_string<TCHAR> strEmpty;
ASSERT(pSettings != NULL);
if(pSettings == NULL) return strEmpty;
std::vector<BYTE> s;
s.push_back(PWGD_VERSION_BYTE);
UTF8_BYTE *pbName = _StringToUTF8(pSettings->strName.c_str());
UTF8_BYTE *pb = pbName;
while(*pb != 0) { s.push_back(*pb); ++pb; }
s.push_back(0);
SAFE_DELETE_ARRAY(pbName);
s.push_back(pSettings->btGeneratorType);
s.push_back((pSettings->bCollectUserEntropy == TRUE) ? (BYTE)'U' : (BYTE)'N');
s.push_back((BYTE)((pSettings->dwLength >> 24) & 0xFF));
s.push_back((BYTE)((pSettings->dwLength >> 16) & 0xFF));
s.push_back((BYTE)((pSettings->dwLength >> 8) & 0xFF));
s.push_back((BYTE)(pSettings->dwLength & 0xFF));
PwCharSet pcs(pSettings->strCharSet.c_str());
USHORT usFlags = pcs.PackAndRemoveCharRanges();
s.push_back((BYTE)((usFlags >> 8) & 0xFF));
s.push_back((BYTE)(usFlags & 0xFF));
std::basic_string<WCHAR> strRemChars = pcs.ToString();
for(unsigned int uCS = 0; uCS < strRemChars.size(); ++uCS)
{
s.push_back((BYTE)(strRemChars[uCS] >> 8));
s.push_back((BYTE)(strRemChars[uCS] & 0xFF));
}
s.push_back(0);
s.push_back(0);
for(unsigned int uPat = 0; uPat < pSettings->strPattern.size(); ++uPat)
{
s.push_back((BYTE)(pSettings->strPattern[uPat] >> 8));
s.push_back((BYTE)(pSettings->strPattern[uPat] & 0xFF));
}
s.push_back(0);
s.push_back(0);
s.push_back((BYTE)((pSettings->bNoConfusing == TRUE) ? 'N' : 'A'));
s.push_back((BYTE)((pSettings->bPatternPermute == TRUE) ? 'P' : 'N'));
s.push_back((BYTE)((pSettings->bNoRepeat == TRUE) ? 'N' : 'R'));
for(unsigned int uExc = 0; uExc < pSettings->strExcludeChars.size(); ++uExc)
{
s.push_back((BYTE)(pSettings->strExcludeChars[uExc] >> 8));
s.push_back((BYTE)(pSettings->strExcludeChars[uExc] & 0xFF));
}
s.push_back(0);
s.push_back(0);
DWORD dwOutSize = static_cast<DWORD>(s.size() * 4 + 12);
BYTE *pBase64 = new BYTE[dwOutSize];
if(CBase64Codec::Encode(&s[0], (DWORD)s.size(), pBase64, &dwOutSize) == false)
{
ASSERT(FALSE);
return strEmpty;
}
#ifdef _UNICODE
TCHAR *lpFinal = _StringToUnicode((char *)pBase64);
#else
TCHAR *lpFinal = (TCHAR *)pBase64;
#endif
std::basic_string<TCHAR> strFinal = lpFinal;
SAFE_DELETE_ARRAY(pBase64);
#ifdef _UNICODE
SAFE_DELETE_ARRAY(lpFinal);
#endif
return strFinal;
}
void PwgStringToProfile(const std::basic_string<TCHAR>& strProfile,
PW_GEN_SETTINGS_EX* s)
{
ASSERT(s != NULL); if(s == NULL) return;
PwgGetDefaultProfile(s);
#ifdef _UNICODE
const char *lpEncoded = _StringToAnsi(strProfile.c_str());
std::basic_string<char> strEncoded = lpEncoded;
SAFE_DELETE_ARRAY(lpEncoded);
#else
std::basic_string<char> strEncoded = strProfile.c_str();
#endif
DWORD dwDecodedSize = static_cast<DWORD>(strProfile.size() + 130);
scoped_array<BYTE> pDecoded(new BYTE[dwDecodedSize]);
memset(pDecoded.get(), 0, dwDecodedSize);
if(CBase64Codec::Decode((BYTE *)strEncoded.c_str(),
static_cast<DWORD>(strEncoded.size()), pDecoded.get(),
&dwDecodedSize) == false) { ASSERT(FALSE); return; }
ASSERT(pDecoded.get()[0] <= PWGD_VERSION_BYTE);
TCHAR* lpName = _UTF8ToString(&pDecoded.get()[1]);
s->strName = lpName;
BYTE *pb = (BYTE *)memchr(pDecoded.get(), 0, dwDecodedSize);
if(pb == NULL) { ASSERT(FALSE); return; }
++pb;
s->btGeneratorType = *pb; ++pb;
s->bCollectUserEntropy = ((*pb == (BYTE)'U') ? TRUE : FALSE); ++pb;
s->dwLength = (static_cast<DWORD>(*pb) << 24); ++pb;
s->dwLength |= (static_cast<DWORD>(*pb) << 16); ++pb;
s->dwLength |= (static_cast<DWORD>(*pb) << 8); ++pb;
s->dwLength |= static_cast<DWORD>(*pb); ++pb;
USHORT usFlags = (USHORT)(*pb) << 8; ++pb;
usFlags |= (USHORT)(*pb); ++pb;
PwCharSet pcs;
pcs.UnpackCharRanges(usFlags);
while(true)
{
BYTE bt1 = *pb; ++pb;
BYTE bt2 = *pb; ++pb;
if((bt1 == 0) && (bt2 == 0)) break;
pcs.Add(((WCHAR)bt1 << 8) | (WCHAR)bt2);
}
s->strCharSet = pcs.ToString();
while(true)
{
BYTE bt1 = *pb; ++pb;
BYTE bt2 = *pb; ++pb;
if((bt1 == 0) && (bt2 == 0)) break;
s->strPattern += (WCHAR)(((WCHAR)bt1 << 8) | (WCHAR)bt2);
}
ASSERT((*pb == (BYTE)'N') || (*pb == (BYTE)'A'));
s->bNoConfusing = ((*pb == (BYTE)'N') ? TRUE : FALSE); ++pb;
ASSERT((*pb == (BYTE)'P') || (*pb == (BYTE)'N') || (*pb == 0));
s->bPatternPermute = ((*pb == (BYTE)'P') ? TRUE : FALSE); ++pb;
ASSERT((*pb == (BYTE)'N') || (*pb == (BYTE)'R') || (*pb == 0));
s->bNoRepeat = ((*pb == (BYTE)'N') ? TRUE : FALSE); ++pb;
while(true)
{
BYTE bt1 = *pb; ++pb;
BYTE bt2 = *pb; ++pb;
if((bt1 == 0) && (bt2 == 0)) break;
s->strExcludeChars += (WCHAR)(((WCHAR)bt1 << 8) | (WCHAR)bt2);
}
SAFE_DELETE_ARRAY(lpName);
}
void PwgGetDefaultProfile(PW_GEN_SETTINGS_EX* s)
{
ASSERT(s != NULL); if(s == NULL) return;
s->strName.clear();
s->btGeneratorType = PWGT_CHARSET;
s->bCollectUserEntropy = FALSE;
s->dwLength = 20;
PwCharSet pcs;
pcs.Add(PDCS_UPPER_CASE, PDCS_LOWER_CASE, PDCS_NUMERIC);
s->strCharSet = pcs.ToString();
s->strPattern.clear();
s->bPatternPermute = FALSE;
s->bNoConfusing = FALSE;
s->bNoRepeat = FALSE;
s->strExcludeChars.clear();
}
BOOL PwgHasSecurityReducingOption(const PW_GEN_SETTINGS_EX* pSettings)
{
ASSERT(pSettings != NULL); if(pSettings == NULL) return FALSE;
if(pSettings->bNoConfusing != FALSE) return TRUE;
if(pSettings->bNoRepeat != FALSE) return TRUE;
if(pSettings->strExcludeChars.size() > 0) return TRUE;
return FALSE;
}
©版权声明:本文内容由互联网用户自发贡献,版权归原创作者所有,本站不拥有所有权,也不承担相关法律责任。如果您发现本站中有涉嫌抄袭的内容,欢迎发送邮件至: www_apollocode_net@163.com 进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
转载请注明出处: apollocode » KeePass
文件列表(部分)
名称 | 大小 | 修改日期 |
---|---|---|
Chinese_Simplified.lng | 46.29 KB | 2015-06-16 |
KeePass-1.001╘¡╩╝╨▐╒²░µVC2010.rar | 27,443.53 KB | 2015-06-44 |
发表评论 取消回复