Looking at the example in Request Format|Documentation
there are two different values for the value of Key.
In the text it says key = 23e9d89a967a5f18142221fa87cb5d0):
Yet in the code is key = “23e9d89a967a5f18142221fa87cb5d0”;
I am trying to build a prototype in Delphi but cannot get the value quoted for the hash value. I then tried taking the C# code directly from the page and got the same value for the hash as I did in Delphi.
This table presents my results.
URL: | http://api.aspose.com/1.1/storage/folder/test_folder |
|||
---|---|---|---|---|
SID: | c821f123-1a8b-4b97-925a-9a6b2fcd8 | |||
Passed to SHA1 Hash function: | http://api.aspose.com/1.1/storage/folder/test_folder?appSID=c821f123-1a8b-4b97-922a-9d69a2fcd8 |
|||
Results after Hash (step 4) | ||||
Documented ?? | C# | Delphi | ||
Key: | 23e9d89a967a5f18142221f9f7cbcd0 | Z98TBrlwdtx3pTa6fWVD/Q0c2dE= | JgLReiOyORY8BYpCJ32CbCc0UHg | JgLReiOyORY8BYpCJ32CbCc0UHg |
23e9d89a967a5f18142221f9f7cbcd0): | Z98TBrlwdtx3pTa6fWVD/Q0c2dE= | psj/voj0uG7xvKXXM5rt63hAEic= | psj/voj0uG7xvKXXM5rt63hAEic= |
I have spent over a day trying to work this out - what am I doing wrong or is the example given wrong?
Delphi code:
procedure TAsposeAuthenticator.DoAuthenticate( ARequest : TCustomRESTRequest );
var
hashed : TIdBytes;
req, sign : AnsiString;
begin
req := AnsiString( ARequest.Resource );
req := req + AnsiString( '?appSID=' ) + mySID;
req := RemoveTrailing( '/', req );
with TIdHMACSHA1.Create do
try
Key := ToBytes( myKey );
hashed := HashValue( ToBytes( req ) );
finally
Free;
end;
sign := RemoveTrailing( '=', EncodeBase64( hashed, Length( hashed ) ) );
sign := TURI.urlEncode( sign ); // codes are produced in upper case
req := req + AnsiString( '&Signature=' ) + sign;
end;
procedure TestAuthenticator( ARequest : TCustomRESTRequest );
var
Authenticator : TAsposeAuthenticator;
begin
Authenticator := TAsposeAuthenticator.Create( ARequest, 'c821f123-1a8b-4b97-925a-9d69a6b2fcd8', '23e9d89a967a5f18142221fa8f7cbcd0' );
Authenticator.DoAuthenticate( ARequest );
if StrPos( ARequest.Resource, '' ) > 0 then
ShowMessage( ARequest.Resource + #10#13'Passed' )
else
ShowMessage( ARequest.Resource + #10#13'Failed' );
end;