I am using Delphi XE2 and the code below to create an MD5 base5 hash for use with Amazon MWS. It works if I compile it for 32-bit Windows, but if I compile for 64-bit windows, the hash is returned. What causes this and how can I change this so that they return the same hash?
function getMd5HashString(value: string): string; var MessageDigest: TIdHashMessageDigest5; Content: TBytes; begin Content := TEncoding.UTF8.GetBytes(value); MessageDigest:=TIdHashMessageDigest5.Create; Result:=Data.Cloud.CloudAPI.EncodeBytes64(MessageDigest.HashBytes(Content)); end;
Thansk in advance.
Edit:
I use the above function in the following test:
procedure Button1Click(Sender: TObject); begin Edit2.Text := getMd5HashString(Edit1.Text); end;
Skipping
<?xml version="1.0" encoding="utf-8"?>
as a string, just for verification. If I compile a program with a 32-bit Windows target platform, the returned hash will be:
I3pK / R + hpYOKY1IQRviZbQ ==
If I compile a program with the target platform of Windows 64-bit, I get:
bmkkAOXGhLdDFCUuNBuSxw ==
Hope David answers you?
Edit2: the complete program proposed by David;
unit ContentHashTest; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.Cloud.CloudAPI, IdGlobal, IdHash, IdHashMessageDigest, IdCoder, IdCoderMIME, Vcl.StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Edit2: TEdit; procedure Button1Click(Sender: TObject); private function getMd5HashString(value: string): string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Edit2.Text := getMd5HashString(Edit1.Text); end; function TForm1.getMd5HashString(value: string): string; var MessageDigest: TIdHashMessageDigest5; Content: TBytes; begin Content := TEncoding.UTF8.GetBytes(value); MessageDigest:=TIdHashMessageDigest5.Create; Result:=Data.Cloud.CloudAPI.EncodeBytes64(MessageDigest.HashBytes(Content)); end; end.
It was my attempt to start. Following David's suggestion below, I changed this to:
unit ContentHashTest; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdGlobal, IdHash, IdHashMessageDigest, IdCoder, IdCoderMIME, Vcl.StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Edit2: TEdit; procedure Button1Click(Sender: TObject); private function getMd5HashString(value: string): string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Edit2.Text := getMd5HashString(Edit1.Text); end; function TForm1.getMd5HashString(value: string): string; var MessageDigest: TIdHashMessageDigest5; Content: TIdBytes; begin Content := TIdTextEncoding.UTF8.GetBytes(value); MessageDigest := TIdHashMessageDigest5.Create; try Result := TIdEncoderMIME.EncodeBytes(MessageDigest.HashBytes(Content)); finally MessageDigest.Free; end; end; end.
Unfortunately, with the same different results.
Win32 = I3pK / R + hpYOKY1IQRviZbQ ==
Win64 = bmkkAOXGhLdDFCUuNBuSxw ==