@@ -0,0 +1,1494 @@
+package com.qiniu.qbox.auth;%0A%0Aimport javax.crypto.Mac;%0Aimport javax.crypto.spec.SecretKeySpec;%0A%0Aimport org.json.JSONException;%0Aimport org.json.JSONStringer;%0A%0Aimport com.qiniu.qbox.Config;%0A%0Apublic final class DownloadPolicy %7B%0A%0A%09private long deadLine;%0A%09private String pattern;%0A%0A%09public DownloadPolicy(long deadLine, String pattern) %7B%0A%09%09%0A%09%09if (deadLine %3C= 0) %7B%0A%09%09%09deadLine = 3600; // set to default value, an hour%0A%09%09%7D%0A%09%09if (pattern == null %7C%7C pattern.trim().length() == 0) %7B%0A%09%09%09pattern = %22*/*%22; // set to default.%0A%09%09%7D%0A%09%09this.deadLine = deadLine;%0A%09%09this.pattern = pattern;%0A%09%7D%0A%0A%09private String makeScope() throws JSONException %7B%0A%09%09%0A%09%09long expires = System.currentTimeMillis() / 1000 + this.deadLine;%0A%09%09String jsonScope = new JSONStringer().object().key(%22S%22)%0A%09%09%09%09.value(this.pattern).key(%22E%22).value(expires).endObject()%0A%09%09%09%09.toString();%0A%0A%09%09return Client.urlsafeEncode(jsonScope);%0A%09%7D%0A%0A%09private byte%5B%5D makeHmac(String scope) throws Exception %7B%0A%0A%09%09Mac mac = Mac.getInstance(%22HmacSHA1%22);%0A%09%09byte%5B%5D secretKey = Config.SECRET_KEY.getBytes();%0A%09%09SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, %22HmacSHA1%22);%0A%09%09mac.init(secretKeySpec);%0A%09%09mac.update(scope.getBytes());%0A%0A%09%09return mac.doFinal();%0A%09%7D%0A%0A%09private String checksum(byte%5B%5D hmac) throws Exception %7B%0A%0A%09%09return Client.urlsafeEncodeString(hmac);%0A%09%7D%0A%0A%09public String makeDownloadToken() throws Exception %7B%0A%0A%09%09String scope = makeScope();%0A%09%09String checksum = checksum(makeHmac(scope));%0A%0A%09%09return Config.ACCESS_KEY + %22:%22 + checksum + %22:%22 + scope;%0A%09%7D%0A%0A%7D%0A

support download private file with downloadtoken