2

I'm trying to generate a key for decoding a password that has been encrypted using ColdFusion. Im getting different result when im passing param in binaryDecode(string, "hex"). How do I translate this into JavaScript?

in ColdFusion:

binaryDecode("CA993CED42F374C9291FC2484495CD9334E8C822", "hex")   
output is: -54-10360-1966-13116-554131-627268-107-51-10952-24-5634 (binary)  
after that the output will be looped and store in array variable 
then binaryEncode(javaCast("byte[]", arrayVariable), "Base64") 
the result is generatedKey



in Node js:
i didnt get the same output after the binaryDecode
43413939334345443432463337344339323931464332343834343935434439333334453843383232
I tried using `buffer.from()` but it just split to `43 41 39` etc. 

I've tried so many things but I'm unable to get that -54-10360-1966-13116-554131-627268-107-51-10952-24-5634 result

3
  • Does this answer your question? How to convert hex string into a bytes array, and a bytes array in the hex string? Commented Jan 15, 2020 at 15:27
  • 1
    Are you sure you are looking at the correct ColdFusion code? You say that you are trying to "decode" a password but the binaryDecode() function is not used for encryption. It is used to convert string data back into binary data. Commented Jan 15, 2020 at 16:15
  • yes the return of binaryDecode will be used as a key for decoding encryption, but i just realize the CA993CED42F374C9291FC2484495CD9334E8C822 needs to be converted to hexadecimal bytes, then i need to BASE64 encoding, i notice from cryptii.com/pipes/base64-to-hex, i just didnt understand what that binaryDecode did Commented Jan 15, 2020 at 16:25

2 Answers 2

2

This is not coldfusion binaryDecode. More likely some output system just print in this format. Other words this is just convert char to sbyte. But If you want try this code

function convert(h) {
    h = h.split('');
    const r = [];
    for(let i=0; i<h.length; i+=2) {
        r.push(parseInt(h[i]+h[i+1], 16));
    }
    return r.map(e => e > 127 ? -(256-e): e).join('')
}


console.log(convert("CA993CED42F374C9291FC2484495CD9334E8C822"));

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, but i think i realize, where my problem is, i just need to change the CA993CED42F374C9291FC2484495CD9334E8C822 byte hex, and base64 encoding, i will update my solution
1

i found what i was looking for

var btoa = require('btoa');

const  a= 'CA993CED42F374C9291FC2484495CD9334E8C822';
const f = Buffer.from(a, 'hex');
console.log(f);

const base64String = btoa(String.fromCharCode.apply(null, new Uint8Array(f)));

console.log(base64String);

thanks anyways for the help

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.