unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, InvokeRegistry, Rio, SOAPHTTPClient, AWSECommerceService, StdCtrls,
himXML, DECUtil, DECCipher, DECHash, DECFmt,HMAC, Hash, SHA256, mem_util;
const
AWSID = '
gelöscht';
sAWSID = '
gelöscht';
sACCES_ID = '
gelöscht';
type
TForm1 =
class(TForm)
Button1: TButton;
HTTPRIO1: THTTPRIO;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure HTTPRIO1BeforeExecute(
const MethodName:
string;
SOAPRequest: TStream);
private
function GenerateCurrentTimeStamp:
string;
function GenerateHMACSignature(Text, key: ansistring): ansistring;
function concat(c: Char; l: Integer):
String;
function SimpleCryptString(
const S, Key:
string):
string;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
AWSPort: AWSECommerceServicePortType;
AmazonPort: AWSECommerceServicePortType;
body: ItemSearch;
arr_request: Array_Of_ItemSearchRequest;
aRequest: ItemSearchRequest;
aResponse: ItemSearchResponse;
i: Integer;
j: Integer;
begin
AWSPort := GetAWSECommerceServicePortType(False,'
',HTTPRIO1);
body := ItemSearch.Create;
body.AWSAccessKeyId := AWSID;
body.SubscriptionId := sACCES_ID;
body.AssociateTag := sACCES_ID;
aRequest := ItemSearchrequest.Create;
aRequest.SearchIndex := '
Video';
aRequest.Title := '
Matrix';
SetLength(arr_request, 1);
arr_request[0] := aRequest;
body.Request := arr_request;
aResponse := AWSPort.ItemSearch(body);
for i := 0
to Length(aResponse.Items) - 1
do
for j := 0
to Length(aResponse.Items[i].Item) - 1
do
begin
Memo1.Lines.Add(aResponse.Items[i].Item[j].ItemAttributes.Title);
end;
end;
function TForm1.GenerateCurrentTimeStamp():
string;
var
TimeStamp:
string;
y,mon,d,h,m,s,ms: Word;
begin
DecodeDate(Now,y,mon,d);
DecodeTime(Now,h,m,s,ms);
// 2009-02-16T17:39:51.000Z
Result := Format('
%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.000Z',[y,mon,d,h,m,s]);
end;
function TForm1.concat(c: Char; l: Integer):
String;
var
I: Integer;
begin
Result := '
';
for I := 0
to l-1
do
Result := '
0' + Result;
end;
function TForm1.SimpleCryptString(
const S, Key:
string):
string;
var
i, j: Integer;
C: Byte;
P: PByte;
begin
SetLength(Result, Length(S));
P := PByte(Result);
j := 1;
for i := 1
to Length(S)
do
begin
C := Ord(S[i]);
C := C
xor Ord(Key[j]);
P^ := C;
Inc(P);
Inc(j);
if j > Length(Key)
then
j := 1;
end;
end;
function TForm1.GenerateHMACSignature(Text, key: ansistring): ansistring;
var
ctx: THMAC_Context;
phash: PHashDesc;
mac: THashDigest;
begin
phash := FindHash_by_Name('
SHA256');
if phash =
nil then begin
{Action for 'Hash function not found/registered.'}
exit;
end;
hmac_init(ctx, phash, @key[1], length(key));
hmac_update(ctx, @Text[1], length(Text));
hmac_final(ctx, mac);
// Result := HexStr(@mac, sizeof(mac));
Result := Base64Str(@mac, sizeof(TSHA256Digest));
end;
procedure TForm1.HTTPRIO1BeforeExecute(
const MethodName:
string;
SOAPRequest: TStream);
var
XML: TXMLFile;
Node: TXMLNode;
S: ansistring;
begin
SOAPRequest.Seek(0,0);
XML := TXMLFile.Create(Self,false);
xml.LoadFromStream(SOAPRequest);
Node :=
XML.RootNode.Node['
SOAP-ENV:Body'].Node['
ItemSearch'];
Node.AddNode('
Timestamp').Text := GenerateCurrentTimeStamp;
Node.AddNode('
Action').Text := '
ItemSearch';
Node.AddNode('
Signature').Text_Base64w := GenerateHMACSignature('
ItemSearch',Node.Node['
Timestamp'].Text);
SOAPRequest.Seek(0,0);
xml.SaveToStream(SOAPRequest);
xml.SaveToXML(S);
Memo1.Text := S;
Application.Processmessages;
end;