运用七牛java-sdk图片处置惩罚做另存

//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();
    }
}
    原文作者:三木
    原文地址: https://segmentfault.com/a/1190000007974956
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞