Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
decryptHexToBuffer(cipher) {
assert(cipher, "Missing cipher text");
// Convert data into word arrays (used by Crypto)
var cipher_array = encHex.parse(cipher);
var plainwords = this._decrypt_word_array(cipher_array);
var plainhex = encHex.stringify(plainwords);
return new Buffer(plainhex, 'hex');
}
decryptHexToBuffer(cipher) {
assert(cipher, "Missing cipher text");
// Convert data into word arrays (used by Crypto)
var cipher_array = encHex.parse(cipher);
var plainwords = this._decrypt_word_array(cipher_array);
var plainhex = encHex.stringify(plainwords);
return new Buffer(plainhex, "hex");
}
decryptHex(cipher) {
assert(cipher, "Missing cipher text");
// Convert data into word arrays (used by Crypto)
var cipher_array = encHex.parse(cipher);
var plainwords = this._decrypt_word_array(cipher_array);
return encHex.stringify(plainwords);
}
decryptHex(cipher) {
assert(cipher, "Missing cipher text");
// Convert data into word arrays (used by Crypto)
var cipher_array = encHex.parse(cipher);
var plainwords = this._decrypt_word_array(cipher_array);
return encHex.stringify(plainwords);
}
getHeader() {
// Generate the request string
const canonicalHeaders = `content-type:${ContentType}\nhost:${this.host}\n`;
const signedHeaders = 'content-type;host';
const hashedRequestPayload = Hex.stringify(SHA256(this.payload)).toLowerCase();
const canonicalRequest = `${HttpRequestMethod}\n${CanonicalUri}\n${CanonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${hashedRequestPayload}`;
// Generate the original signature string
const credentialScope = `${this.date}/${this.service}/tc3_request`;
const hashedCanonicalRequest = Hex.stringify(SHA256(canonicalRequest)).toLowerCase();
const stringToSign = `${Algorithm}\n${this.timestamp}\n${credentialScope}\n${hashedCanonicalRequest}`;
// Generate the signature string
const secretDate = HmacSHA256(this.date,`TC3${this.secretKey}`);
const secretService = HmacSHA256(this.service, secretDate);
const secretSigning = HmacSHA256('tc3_request', secretService);
const signature = Hex.stringify(HmacSHA256(stringToSign,secretSigning));
// Generate the authorization string
const authorization = `${Algorithm} Credential=${this.secretId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
// Common Request Parameters of the header information
const headers = {
"Authorization": authorization,
"Content-Type": ContentType,
"X-TC-Action": this.action,
encryptHex(plainhex) {
var plain_array = encHex.parse(plainhex);
var cipher_array = this._encrypt_word_array(plain_array);
return encHex.stringify(cipher_array);
}
}
atHash,
cb
) {
if (this.expectedAlg !== alg) {
return cb(
new error.TokenValidationError(
'Signature algorithm of "' +
alg +
'" is not supported. Expected "' +
this.expectedAlg +
'"'
)
);
}
var sha256AccessToken = sha256(accessToken);
var hashToHex = cryptoHex.stringify(sha256AccessToken);
var hashToHexFirstHalf = hashToHex.substring(0, hashToHex.length / 2);
var hashFirstHalfWordArray = cryptoHex.parse(hashToHexFirstHalf);
var hashFirstHalfBase64 = cryptoBase64.stringify(hashFirstHalfWordArray);
var hashFirstHalfBase64SafeUrl = base64.base64ToBase64Url(
hashFirstHalfBase64
);
if (hashFirstHalfBase64SafeUrl !== atHash) {
return cb(new error.TokenValidationError('Invalid access_token'));
}
return cb(null);
};
private getVarName(): string {
return `__internal_${hex.stringify(sha256(this.extensionName))}`;
}
getVarName(prefix: string = '__internal_'): string {
return `${prefix}${hex.stringify(sha256('TwingParser::getVarName' + this.stream.getSourceContext().getCode() + this.varNameSalt++))}`;
}