On Nov 7, 2013, at 2:15 AM, Du Jun <dj199...@gmail.com> wrote: > Hi, > I have both apikey and secretkey,and I use the following code to > generate signature: > > package test; > import javax.crypto.Mac; > import javax.crypto.spec.SecretKeySpec; > import org.apache.commons.codec.binary.Base64; > > public class Sign { > public static void main(String args[]) throws Exception{ > String > apikey="zr_w86-A-2TsaDzgEUbJZ1PNICWv8L4H_ywHcIwgHX186nAbpHVn4c-FLuAbRjjzVt9r890HE-me_lNDc7yxMw"; > String request=("apikey="+apikey+"&command=listZones").toLowerCase(); > String > secret="w4ZW_kQeEtmfbLOeBz6Pj39iHUdqlpnfYd62o7bSn3PK7uLElQHE0nCLLRU8i3fu72-vC1JxzmvuEEMxt6WwVQ"; > Mac mac = Mac.getInstance("HmacSHA1"); > SecretKeySpec keySpec = new > SecretKeySpec(secret.getBytes("UTF-8"),"HmacSHA1"); > mac.init(keySpec); > mac.update(request.getBytes()); > byte[] encryptedBytes = mac.doFinal(); > System.out.println(Base64.encodeBase64String(encryptedBytes)); //result > } > } > > I think my signature is correct.Then I generate complete URL: > http://172.17.4.104:8080/client/api?command=listZones&apiKey=zr_w86-A-2TsaDzgEUbJZ1PNICWv8L4H_ywHcIwgHX186nAbpHVn4c-FLuAbRjjzVt9r890HE-me_lNDc7yxMw&signature=jS94Qv63W1h9QGS23zPg3kMIU7o >
I think it's 'apikey' lowercase if that's not the issue, then check your url encoding of all the strings⦠See: https://github.com/runseb/cloudstack-books/blob/master/en/developer.markdown I wrote an example in python. > However,I get the error message as show below: > <listzonesresponse cloud-stack-version="4.0.2.20130501180711"> > <errorcode>401</errorcode> > <errortext>unable to verify user credentials</errortext> > </listzonesresponse> > > I just don't know why?Any reply will be appreciated! > > ----------------------------- > Best regards, > > Frank