我想寫一個簡單的實用程序,從Firefox密碼數據庫中提取密碼(相應文件在配置文件夾中稱爲signons.sqlite
)。解密Firefox密碼數據庫
我到目前爲止所做的:使用sqlite打開的數據庫,檢索的加密用戶名,加密的密碼和網站地址(全部存儲爲std::string
)。
所以,唯一剩下的就是解密用戶名和密碼字符串。
我嘗試以下(PK11Decrypt
應該存儲在plaintext
明文密碼):
void Firefox_Importer::PK11Decrypt(string _cipheredBuffer, char **plaintext) {
// declarations needed
SECItem * request;
SECItem * reply;
unsigned int len = (unsigned int)_cipheredBuffer.length();
const char* cipheredBuffer = (const char*)_cipheredBuffer.c_str();
// generate request and reply SECItem; seems to work properly
reply = SECITEM_AllocItem(NULL, NULL, 0);
if (reply == NULL) cout << "Error allocating SECITEM." << endl;
request = NSSBase64_DecodeBuffer(NULL, NULL, cipheredBuffer, len);
if (request == NULL) cout << "Error decoding buffer." << endl;
// the following is not working
SECStatus tmp = PK11SDR_Decrypt(request, reply, NULL);
if(tmp != SECSuccess) cout << "Something went wrong during decrypting" << endl;
*plaintext = (char*)malloc(reply->len + 1);
strncpy(*plaintext, (const char*)reply->data, reply->len);
(*plaintext)[reply->len] = '\0';
SECITEM_FreeItem(request, true);
SECITEM_FreeItem(reply, true);
}
當PK11Decrypt
被調用時,它打印Something went wrong during decrypting
,表明調用PK11SDR_Decrypt
沒有正常工作。它總是返回SECFailure
(對應於-1)。
有沒有人有一些提示或知道我在做什麼錯?
感謝您的提示。其實我犯了一個愚蠢的錯誤,忘記調用'NSS_Init'。謝謝。 – phimuemue
@AmitKhandelwal:假設您使用的是NSS庫,該代碼可以在任何操作系統上使用。如果你只是想訪問你的機器上的數據庫,你最好在superuser.com上提出一個新問題。 –
如果設置了主密碼,該怎麼辦?可以使用PK11SDR_Decrypt以及已知的主密碼嗎? –