Приветствую всех!
Пишу универсальный менеджер криптопровайдеров Windows.
Возникает ошибка NTE_BAD_DATA при вызове CryptDecrypt.
ICQ#: 283-816-077
Шифрую следующим образом:
procedure Encrypt(in_,out_:TFileName);
var inp_file,out_file:file;
pbBuffer:PByte;
dwBlockLen:DWORD;
dwBufferLen:DWORD;
dwCount:DWORD;
begin
AssignFile(inp_file,in_);
AssignFile(out_file,out_);
Reset(inp_file,1);
Rewrite(out_file,1);
dwBlockLen:=1000 - 1000 mod ENCRYPT_BLOCK_SIZE;
if AlgTypeToStr(CurPar.cAlg_EN.aiAlgid)<>'ïîòî÷íûé' then
dwBufferLen:=dwBlockLen+ENCRYPT_BLOCK_SIZE else
dwBufferLen:=dwBlockLen;
GetMem(pbBuffer,dwBufferLen);
while not Eof(inp_file) do
begin
BlockRead(inp_file,pbBuffer^,dwBlockLen,dwCount);
if CryptEncrypt(key,0,eof(inp_file),0,pbBuffer,@dwCount,dwBufferLen) then
BlockWrite(out_file,pbBuffer^,dwCount) else
ShowErrorMes(GetLastError);
end;
FreeMem(pbBuffer);
CloseFile(inp_file);
CloseFile(out_file);
CryptDestroyKey(key);
end;
Расшифрование:
procedure Decrypt(in_,out_:TFileName);
var inp_file,out_file:file;
pbBuffer:PByte;
dwBlockLen:DWORD;
dwBufferLen:DWORD;
dwCount:DWORD;
begin
AssignFile(inp_file,in_);
AssignFile(out_file,out_);
Reset(inp_file,1);
Rewrite(out_file,1);
dwBlockLen:=1000 - 1000 mod ENCRYPT_BLOCK_SIZE;
dwBufferLen:=dwBlockLen;
GetMem(pbBuffer,dwBufferLen);
while not Eof(inp_file) do
begin
BlockRead(inp_file,pbBuffer^,dwBlockLen,dwCount);
if CryptDecrypt(key,0,eof(inp_file),0,pbBuffer,@dwCount) then //ошибка возникает здесь!!!
BlockWrite(out_file,pbBuffer^,dwCount) else
ShowErrorMes(GetLastError);
end;
FreeMem(pbBuffer);
CloseFile(inp_file);
CloseFile(out_file);
CryptDestroyKey(key);
end;