Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(([key, keyId]) => {
// Calculate HMAC text
let expWindow = (Date.now() / 1000) | 0,
body = request.serializeBody() || '',
text = `${expWindow} ${request.method} ${path} ${body}`,
digest = Base64.stringify(hmacSHA512(text, key));
// Do URL-safe base 64 encoding (replace + and / with - and _, respectively)
let b64Digest = digest.replace(/\+/g, '-').replace(/\//g, '_');
// Set headers on request
request = request.clone({
setHeaders: {
Authorization: `signature=${b64Digest},keyId=${keyId},timestamp=${expWindow}`,
}
});
return request;
})
).flatMap(req => {
// Add user-agent header
parsedHeaders['user-agent'] = util.format(
'qingstor-sdk-js/%s (Node.js %s; %s %s)',
version,
process.version,
process.platform,
process.arch
);
if (this.config.additional_user_agent) {
parsedHeaders['user-agent'] += util.format(' %s', this.config.additional_user_agent);
}
// Add helper for DeleteMultipleObjects
if (operation.api === 'DeleteMultipleObjects') {
parsedHeaders['content-md5'] = Base64.stringify(md5(this.parseRequestBody(operation)));
}
return filterUnsafeHeaders(parsedHeaders);
}
export const getHash = (site, selectedItem) => {
const { type, id, page } = selectedItem;
const data = JSON.stringify([site, type, id, page]);
return base64.stringify(sha256(JSON.stringify(data))).slice(0, 19);
};
calculateSignature(stringToSign) {
const signature = Base64.stringify(hmacSHA256(stringToSign, this.secret_access_key));
logger.debug('QingStor query request authorization: ' + signature);
return signature;
}
export const getHash = ({ site, type, id, page }) => {
const data = JSON.stringify([site, type, id, page]);
return base64.stringify(sha256(JSON.stringify(data))).slice(0, 19);
};
base64URLEncode: function (str) {
return Base64.stringify(str)
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
},
export const passwordDigest = function passwordDigest(nonce, created, password) {
const rawNonce = new Buffer(nonce || '', 'base64').toString('binary');
return Base64.stringify(sha1(rawNonce + created + password, ''));
};
exports.encrypt = (data, key) => {
const stringifySafe = require('json-stringify-safe');
if (!data || Object.keys(data).length === 0) return null;
let result = stringifySafe(data);
if (data && key) {
const AES = require("crypto-js/aes");
result = result ? AES.encrypt(result, key).toString() : null;
} else {
const Utf8 = require("crypto-js/enc-utf8");
const Base64 = require("crypto-js/enc-base64");
result = Base64.stringify(Utf8.parse(result));
}
return result;
};
exports.decrypt = (data, key) => {
function signString(stringToSign, accessSecret) {
return Base64.stringify(hmacSHA1(stringToSign, accessSecret));
}
async function identify(uri, options) {