I am a little lost on this one...
I have a special key i need to send to a device in a specified format, and i know that what i am doing is wrong - obviously, because i lack the basic understanding of bit stuff in Javascript, i think.
The first step is to generate a random 128 bit number. Since afaik JS characters are 16 bit, the following code should generate a 128 bit string, doesn't it?
private generateSeed()
{
let result = '';
for(let i = 0; i < 8; i++)
result += ((Math.random() * 10) - 1).toString();
return result;
}
After that i need to concatenate the seed and the key, calculate the SHA1 of that and padd that SHA1 to 192 bit with zeroes.
private generateAKey(seed: string)
{
const Provided_KEY = '[32 random characters are in here]';
let concat = seed + Provided_KEY;
let sha1 = crypto.SHA1(concat).toString();
console.log(`SHA1: ${sha1} , Length: ${sha1.length}`);
// Padd to 192 bit/24 bytes
while(sha1.length < 12)
sha1 += '0';
return sha1;
}
But i am totally lost here. I am pretty sure i am wrong with that. Also since the SHA1 i calculate with crypto-js is already 40 characters long this makes no sense for me.
How do i correctly do this?