Форум: "WinAPI";
Текущий архив: 2018.06.03;
Скачать: [xml.tar.bz2];
Внизфункции cryptprotectdata Найти похожие ветки
← →
Tima (2010-11-04 02:56) [0]Всем привет, требуется кодировать и раскодировать текст функциями cryptprotectdata и cryptunprotectdata, какой то код нашел по теме, но не фурычит прошу помочь привести его в норм состояние:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
CRYPTPROTECT_LOCAL_MACHINE = 4; // ??
type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCharArray = Array[0..1023] Of Char;
_TOKEN_USER = record
User: SID_AND_ATTRIBUTES;
end;
TOKEN_USER = _TOKEN_USER;
TTokenUser = TOKEN_USER;
PTokenUser = ^TOKEN_USER;
_CREDENTIAL_ATTRIBUTEA = record
Keyword: LPSTR;
Flags: DWORD;
ValueSize: DWORD;
Value: PBYTE;
end;
PCREDENTIAL_ATTRIBUTE = ^_CREDENTIAL_ATTRIBUTEA;
_CREDENTIALA = record
Flags: DWORD;
Type_: DWORD;
TargetName: LPSTR;
Comment: LPSTR;
LastWritten: FILETIME;
CredentialBlobSize: DWORD;
CredentialBlob: PBYTE;
Persist: DWORD;
AttributeCount: DWORD;
Attributes: PCREDENTIAL_ATTRIBUTE;
TargetAlias: LPSTR;
UserName: LPSTR;
end;
PCREDENTIAL = array of ^_CREDENTIALA;
_CRYPTPROTECT_PROMPTSTRUCT = record
cbSize: DWORD;
dwPromptFlags: DWORD;
hwndApp: HWND;
szPrompt: LPCWSTR;
end;
PCRYPTPROTECT_PROMPTSTRUCT = ^_CRYPTPROTECT_PROMPTSTRUCT;
_CRYPTOAPI_BLOB = record
cbData: DWORD;
pbData: PBYTE;
end;
DATA_BLOB = _CRYPTOAPI_BLOB;
PDATA_BLOB = ^DATA_BLOB; // ??
var
Form2: TForm2;
{
CryptProtectData
http://msdn.microsoft.com/en-us/library/aa380261%28VS.85%29.aspx
BOOL WINAPI CryptProtectData(
__in DATA_BLOB *pDataIn,
__in LPCWSTR szDataDescr,
__in DATA_BLOB *pOptionalEntropy,
__in PVOID pvReserved,
__in_opt CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
__in DWORD dwFlags,
__out DATA_BLOB *pDataOut
);
CryptUnprotectData
http://msdn.microsoft.com/en-us/library/aa380882%28VS.85%29.aspx
BOOL WINAPI CryptUnprotectData(
__in DATA_BLOB *pDataIn,
__out_opt LPWSTR *ppszDataDescr,
__in_opt DATA_BLOB *pOptionalEntropy,
__in PVOID pvReserved,
__in_opt CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
__in DWORD dwFlags,
__out DATA_BLOB *pDataOut
);
}
function CryptProtectData(pDataIn: PDATABLOB;
ppszDataDescr: PLPCWSTR;//?? Error
pOptionalEntropy: PDATA_BLOB;
pvReserved: Pointer;
pPromptStruct: PCRYPTPROTECT_PROMPTSTRUCT;
dwFlags: DWORD;
pDataOut: PDATA_BLOB)
: BOOL;
stdcall;
external "crypt32.dll" Name "CryptProtectData";
function CryptUnprotectData(pDataIn: PDATA_BLOB;
ppszDataDescr: PLPWSTR;
pOptionalEntropy: PDATA_BLOB;
pvReserved: Pointer;
pPromptStruct: PCRYPTPROTECT_PROMPTSTRUCT;
dwFlags: DWORD;
pDataOut: PDATA_BLOB)
: BOOL;
stdcall;
external "crypt32.dll" Name "CryptUnprotectData";
implementation
{$R *.dfm}
function EncryptPassword(Password: string): string;
var
DataIn: DATA_BLOB;
dwFlags: DWORD;
DataOut: DATA_BLOB;
I: Integer;
P: PByte;
begin
Result := "";
DataIn.cbData := Length(Password);
DataIn.pbData := Pointer(PChar(Password));
dwFlags := CRYPTPROTECT_LOCAL_MACHINE;
if CryptProtectData(@DataIn, "Password", nil, nil, nil, dwFlags, DataOut) then begin
P := DataOut.pbData;
I := DataOut.cbData;
Result := IntToHex(I, 8);
while (I > 0) do begin
Dec(I);
Result := Result + IntToHex(P^, 2);
Inc(P);
end;
LocalFree(Cardinal(DataOut.pbData));
end;
end;
function DecryptPassword(Password: string): string;
var
DataIn: DATA_BLOB;
dwFlags: DWORD;
DataOut: DATA_BLOB;
I, J: Integer;
P: PByte;
DataDescr: LPWSTR;
begin
Result := "";
if (Length(Password) > 0) then begin
DataIn.cbData := StrToIntDef("$" + Copy(Password, 1, 8), 0);
if (DataIn.cbData > 0) then begin
GetMem(DataIn.pbData, DataIn.cbData);
I := DataIn.cbData;
J := 9;
P := DataIn.pbData;
while (I > 0) and (J < Length(Password)) do begin
Dec(I);
P^ := StrToInt("$" + Copy(Password, J, 2));
Inc(P);
Inc(J, 2);
end;
dwFlags := CRYPTPROTECT_LOCAL_MACHINE;
if CryptUnprotectData(@DataIn, DataDescr, nil, nil, nil, dwFlags, DataOut) then begin
Result := Copy(string(DataOut.pbData), 0, DataOut.cbData);
LocalFree(Cardinal(DataOut.pbData));
end;
end;
end;
end;
← →
Tima (2010-11-04 02:57) [1]Первая ошибка тут:
function CryptProtectData(pDataIn: PDATABLOB;
ppszDataDescr: PLPCWSTR;//?? Error
pOptionalEntropy: PDATA_BLOB;
pvReserved: Pointer;
pPromptStruct: PCRYPTPROTECT_PROMPTSTRUCT;
dwFlags: DWORD;
pDataOut: PDATA_BLOB)
: BOOL;
stdcall;
external "crypt32.dll" Name "CryptProtectData";
← →
Сергей М. © (2010-11-04 20:51) [2]
> ppszDataDescr: PLPCWSTR;//?? Error
pDataDescr: PWideChar;
← →
Tima (2010-11-04 21:37) [3]Спасибо, теперь ошибка в функции
function EncryptPassword(Password: string): string;
в строчкеif CryptProtectData(@DataIn, "Password", nil, nil, nil, dwFlags, DataOut) then begin
ругается мол
[Error] Unit1.pas(94): Incompatible types: "_CRYPTOAPI_BLOB" and "PDATA_BLOB"
[Fatal Error] Project1.dpr(5): Could not compile used unit "Unit1.pas"
← →
Tima (2010-11-04 21:40) [4]@ добавил, там же поинтер)))
← →
wins (2010-11-10 08:36) [5]Всем привет.
Тоже пытаюсь его оживить и не получается:(
постоянно ругается, -
[Error] Unit2.pas(100): Undeclared identifier: "PDATABLOB"
[Error] Unit2.pas(102): Undeclared identifier: "PLPCWSTR"
[Error] Unit2.pas(141): Incompatible types: "_CRYPTOAPI_BLOB" and "PDATA_BLOB"
[Error] Unit2.pas(178): Incompatible types: "WideChar" and "PWideChar"
[Error] Unit2.pas(178): Incompatible types: "_CRYPTOAPI_BLOB" and "PDATA_BLOB"
[Error] Unit2.pas(187): Declaration expected but end of file found
[Error] Unit2.pas(18): Unsatisfied forward or external declaration: "TForm2.Button1Click"
[Error] Unit2.pas(19): Unsatisfied forward or external declaration: "TForm2.Button2Click"
[Fatal Error] Project1.dpr(6): Could not compile used unit "Unit2.pas"
Может кто поправит скрипт или выложит рабочюю версию проекта, оч нада.
Может у меня в делфях (7-ка) компонента какого не хватает?
Спасибо.
← →
Anatoly Podgoretsky © (2010-11-10 09:18) [6]> wins (10.11.2010 08:36:05) [5]
Как ты умудрился, столько детских ошибок сделать.
← →
wins (2010-11-10 09:54) [7]Я новичок в этом деле:( только начинаю разбираться...
← →
wins (2010-11-10 09:55) [8]Просто скопировал скрипт в проект и запустил его....
← →
neversleep (2010-11-10 15:01) [9]
> A: Как ты умудрился, столько детских ошибок сделать.
> B: Просто скопировал скрипт в проект и запустил его....
ИМХО в орешник :)))
← →
wins (2010-11-10 20:44) [10]Вообще-то нужна была помощь, а не цитаты и ленивые отписки... считаю если человек способен помочь,- поможет; если не может, то пусть не блещет некомпетентностью.
Всем спасибо.
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2018.06.03;
Скачать: [xml.tar.bz2];
Память: 0.49 MB
Время: 0.002 c