demo/common/cos-auth.js
function (opt) {
        var pathname = opt.Pathname || '/';
        var expires = opt.Expires;

        var ShortBucketName = '';
        var AppId = '';
        var match = opt.Bucket.match(/^(.+)-(\d+)$/);
        if (match) {
            ShortBucketName = match[1];
            AppId = match[2];
        }

        var random = parseInt(Math.random() * Math.pow(2, 32));
        var now = parseInt(Date.now() / 1000);
        var e = now + (expires === undefined ? 900 : (expires * 1 || 0)); // 默认签名过期时间为当前时间 + 900s
        var path = '/' + AppId + '/' + ShortBucketName + encodeURIComponent(pathname).replace(/%2F/g, '/'); //多次签名这里填空
        var plainText = 'a=' + AppId + '&b=' + ShortBucketName + '&k=' + opt.SecretId + '&e=' + e + '&t=' + now + '&r=' + random + '&f=' + path;
        var sha1Res = CryptoJS.HmacSHA1(plainText, opt.SecretKey);
        var strWordArray = CryptoJS.enc.Utf8.parse(plainText);
        var resWordArray = sha1Res.concat(strWordArray);
        var sign = resWordArray.toString(CryptoJS.enc.Base64);

        return sign;
    }
function (opt) {
        var pathname = opt.Pathname || '/';
        var expires = opt.Expires;

        var ShortBucketName = '';
        var AppId = '';
        var match = opt.Bucket.match(/^(.+)-(\d+)$/);
        if (match) {
            ShortBucketName = match[1];
            AppId = match[2];
        }

        var random = parseInt(Math.random() * Math.pow(2, 32));
        var now = parseInt(Date.now() / 1000);
        var e = now + (expires === undefined ? 900 : (expires * 1 || 0)); // 默认签名过期时间为当前时间 + 900s
        var path = '/' + AppId + '/' + ShortBucketName + encodeURIComponent(pathname).replace(/%2F/g, '/'); //多次签名这里填空
        var plainText = 'a=' + AppId + '&b=' + ShortBucketName + '&k=' + opt.SecretId + '&e=' + e + '&t=' + now + '&r=' + random + '&f=' + path;
        var sha1Res = CryptoJS.HmacSHA1(plainText, opt.SecretKey);
        var strWordArray = CryptoJS.enc.Utf8.parse(plainText);
        var resWordArray = sha1Res.concat(strWordArray);
        var sign = resWordArray.toString(CryptoJS.enc.Base64);

        return sign;
    }
v4 签名