//http://developer.qiniu.com/code/v6/api/dora-api/saveas.html#示例 
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import com.qiniu.util.StringUtils;
import com.qiniu.util.UrlSafeBase64;

public class SaveasDemo {
    public static void tokendownload() throws NoSuchAlgorithmException, InvalidKeyException{

        String ACCESS_KEY = "xxxx";
        String SECRET_KEY = "xxxx";

        String urlbase64 = UrlSafeBase64.encodeToString("javademo:123456aaa.jpg");
        String DownloadUrl  = "7xrnxn.com1.z0.glb.clouddn.com/QQ20160402-2.png?imageMogr2/crop/!300x300a10a10|saveas/"+urlbase64;
        Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");
        mac.init(new SecretKeySpec(StringUtils.utf8Bytes(SECRET_KEY),"HmacSHA1"));
        String t2 = UrlSafeBase64.encodeToString(mac.doFinal(StringUtils.utf8Bytes(DownloadUrl)));

        System.out.println(DownloadUrl+"/sign/"+ACCESS_KEY+":"+t2); 
    }
    public static void main(String args[]) throws InvalidKeyException, NoSuchAlgorithmException{
        tokendownload();
    }
}

三木
208 声望6 粉丝

不开心,你就跳一跳,😊