使用Delphi创建Google-Maps-API签名

时间:2016-09-05 13:06:07

标签: delphi google-maps-api-3

我想为我的地图工作中的clientid创建签名。我需要让我的clientid运行geolocation-api。例如,调用API如下:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&client=gme-myPersonalclientid&signature=HereIsMyProblem

我从我的Delphi应用程序中调用此链接。

我尝试将phyton / java / c#从官方帮助站点(https://developers.google.com/maps/documentation/static-maps/get-api-key?hl=en)传输到Delphi,但我仍然遗漏了一些东西。

function TMgrGoogleMap.SignUrl(AUrl: String): String;
Var
  CryptoKey: String;
  Signature: String;
  HMac: TIdHMACSHA1;
  CryptoIDByte: TBytes;
  SignatureHash: TidBytes;
begin
  //  IdSSLOpenSSL.LoadOpenSSLLibrary;  // not sure if needed, think not

  CryptoKey := 'ARandomKryptoKeyfY1XbqTib1QlY=';
  CryptoIDByte := TNetEncoding.Base64.DecodeStringToBytes(CryptoKey);

  HMac := TIdHMACSHA1.Create;
  HMac.Key := TIdBytes(CryptoIDByte);
  SignatureHash := HMac.HashValue(TidBytes(AUrl));

  Signature := TNetEncoding.Base64.EncodeBytesToString(SignatureHash);

  Result := AUrl + '&signature=' + Signature;
end;

正如谷歌帮助代码示例所示,我首先使用Base64解码我的加密密钥,然后使用编码的加密密钥和网址创建一个带有SHA-1的哈希值。

之后我再次使用Base64对其进行编码,但不幸的是,结果是另一个然后是在线测试https://m4b-url-signer.appspot.com/给出的。

我错过了什么?感谢您提前得到的每一个答案。

0 个答案:

没有答案