|
|
@ -885,7 +885,7 @@ bool Kdb3Database::setFileKey(const QString& filename){ |
|
|
|
error=decodeFileError(file.error()); |
|
|
|
error=decodeFileError(file.error()); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
unsigned long FileSize=file.size(); |
|
|
|
qint64 FileSize=file.size(); |
|
|
|
if(FileSize == 0){ |
|
|
|
if(FileSize == 0){ |
|
|
|
error=tr("Key file is empty."); |
|
|
|
error=tr("Key file is empty."); |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -913,33 +913,32 @@ bool Kdb3Database::setFileKey(const QString& filename){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
SHA256 sha; |
|
|
|
SHA256 sha; |
|
|
|
unsigned char* buffer = new unsigned char[2048]; |
|
|
|
unsigned char* buffer[2048]; |
|
|
|
while(1) |
|
|
|
unsigned long read; |
|
|
|
{ |
|
|
|
do { |
|
|
|
unsigned long read=file.read((char*)buffer,2048); |
|
|
|
read = file.read((char*)buffer,2048); |
|
|
|
if(read == 0) break; |
|
|
|
if (read != 0) |
|
|
|
sha.update(buffer,read); |
|
|
|
sha.update(buffer,read); |
|
|
|
if(read != 2048) break; |
|
|
|
} while (read == 2048); |
|
|
|
} |
|
|
|
|
|
|
|
sha.finish(*RawMasterKey); |
|
|
|
sha.finish(*RawMasterKey); |
|
|
|
RawMasterKey.lock(); |
|
|
|
RawMasterKey.lock(); |
|
|
|
delete [] buffer; |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Kdb3Database::setCompositeKey(const QString& Password,const QString& filename){ |
|
|
|
bool Kdb3Database::setCompositeKey(const QString& Password,const QString& filename){ |
|
|
|
SHA256 sha; |
|
|
|
SHA256 sha; |
|
|
|
|
|
|
|
|
|
|
|
if(!setFileKey(filename))return false; |
|
|
|
setPasswordKey(Password); |
|
|
|
RawMasterKey.unlock(); |
|
|
|
RawMasterKey.unlock(); |
|
|
|
sha.update(*RawMasterKey,32); |
|
|
|
sha.update(*RawMasterKey,32); |
|
|
|
RawMasterKey.lock(); |
|
|
|
RawMasterKey.lock(); |
|
|
|
|
|
|
|
|
|
|
|
setPasswordKey(Password); |
|
|
|
if(!setFileKey(filename))return false; |
|
|
|
RawMasterKey.unlock(); |
|
|
|
RawMasterKey.unlock(); |
|
|
|
sha.update(*RawMasterKey,32); |
|
|
|
sha.update(*RawMasterKey,32); |
|
|
|
sha.finish(*RawMasterKey); |
|
|
|
sha.finish(*RawMasterKey); |
|
|
|
RawMasterKey.lock(); |
|
|
|
RawMasterKey.lock(); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|