0

我已经有了 Cloudstack apikey 和 secretkey,那我该如何生成签名呢?我的 java 程序是:

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="UETJV-Q_G1quXrV84WMHCRbDzWy-ZCUSdtmvsJWdLODMHbfIP4qLQt19CDj_4m1M5yvoZ4I18SdHsBXAtH5Hmw";
            String request=("apikey="+apikey+"&command=listZones").toLowerCase();
            String secret="8q0oR6oPIhB2je9mmgIuuaPJ5mBLkdzsL1BN6OVI8MTfkmW6Y9oHzvlpRiOr5cP612IWH_TTjvfMfKBgKgUMMg";
            Mac mac = Mac.getInstance("HmacSHA1");
            SecretKeySpec keySpec = new SecretKeySpec(secret.getBytes(),"HmacSHA1");
            mac.init(keySpec);
            mac.update(request.getBytes());
            byte[] encryptedBytes = mac.doFinal();

            System.out.println(Base64.encodeBase64String(encryptedBytes));//result
            }
}

HOWVEVR,我就是无法通过凭证。有什么问题吗?

4

1 回答 1

0

您可以使用 cloudmonkey 签名请求方法 https://github.com/apache/cloudstack-cloudmonkey/blob/master/cloudmonkey/requester.py#L203-L214

于 2016-07-22T10:29:52.117 回答