Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const generateApplicationKeySecret = (guid, currentTime) => {
const seed = 'v+Gjs=25Aw5erR!J8ZuvRrCx*rGswhB&qdHd_SYerEWdU&a?3DzN9BRbp5KwY4hEmcj5#fykMjJ=AuWz5GSMY-d@H7DMEh3M@9n2G552Us$$k9cD=3TxwWe86!x#Zyhe';
const algo = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, seed);
const foo = (e) => {
const t = CryptoJS.enc.Base64.stringify(e.finalize());
return t.split('=').join('').split('+').join('-').split('/').join('_');
};
const bar = (e) => {
return Math.floor(e.getTime() / 1000);
};
algo.update(seed);
for(let i = 0; i < (currentTime.getUTCMonth() + 1); i++) {
const l = algo.finalize();
algo.reset();
algo.update(l);
const getToken = (config: Config) => {
let encodedFlags = urlsafeBase64EncodeFlag(config);
let hmac = CryptoJS.algo.AES.createEncryptor(config.secretKey, CryptoJS.SHA1);
const encryptedFlags = hmac.process(encodedFlags);
const words = hmac.finalize();
const base64str = base64_encode(byteArrayToString(wordsToByteArray(words)));
const encodedSign = base64ToUrlSafe(base64str);
return config.accessKey + ':' + encodedSign + ':' + encryptedFlags;
};
function computeContentHash(body: string): string {
const BLOCK_SIZE = 4 * 1024 * 1024;
let hash = cryptoJs.algo.SHA256.create();
for (let i = 0; i < body.length; i += BLOCK_SIZE) {
let chunk = body.substr(i, BLOCK_SIZE);
hash.update(cryptoJs.SHA256(chunk));
}
return hash.finalize().toString();
}
export const generateAuthToken = (username, accessToken, jobId) => {
const hash = CryptoJS.algo.HMAC.create(CryptoJS.algo.MD5, `${username}:${accessToken}`);
hash.update(jobId);
return hash.finalize().toString(CryptoJS.enc.Hex);
};
const getAuthHeader = (apiKey, apiSecret, time, nonce, organizationId = '', request = {}) => {
const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, apiSecret);
hmac.update(apiKey);
hmac.update("\0");
hmac.update(time);
hmac.update("\0");
hmac.update(nonce);
hmac.update("\0");
hmac.update("\0");
if (organizationId) hmac.update(organizationId);
hmac.update("\0");
hmac.update("\0");
hmac.update(request.method);
hmac.update("\0");
hmac.update(request.path);
hmac.update("\0");
if (request.query) hmac.update(typeof request.query == 'object' ? qs.stringify(request.query) : request.query);
let hashobj = function() {
this.sha3 = CryptoJS.algo.SHA3.create({
outputLength: 512
});
this.reset = function() {
this.sha3 = CryptoJS.algo.SHA3.create({
outputLength: 512
});
}
this.update = function(data) {
if (data instanceof BinaryKey) {
let converted = convert.ua2words(data.data, data.data.length);
let result = CryptoJS.enc.Hex.stringify(converted);
this.sha3.update(converted);
} else if (data instanceof Uint8Array) {
let converted = convert.ua2words(data, data.length);