This commit is contained in:
0xturboblitz
2023-08-18 13:25:40 +02:00
parent 72f5e12d76
commit fc149cbb01
2 changed files with 23 additions and 2 deletions

View File

@@ -80,6 +80,15 @@ const md = forge.md.sha256.create();
md.update(forge.util.binary.raw.encode(new Uint8Array(eContent)));
const hashOfEContent = md.digest().getBytes();
console.log('modulus', hexToDecimal(modulus));
console.log('eContent', bytesToBigDecimal(passportData.eContent));
console.log('signature', bytesToBigDecimal(passportData.encryptedDigest));
// Convert the hash to a single decimal number
const hashBigNumber = BigInt('0x' + forge.util.bytesToHex(hashOfEContent));
console.log('hashOfEContent in big decimal', hashBigNumber.toString());
// Signature verification
const signatureBytes = Buffer.from(passportData.encryptedDigest).toString(
'binary',
@@ -97,3 +106,15 @@ function hash(bytesArray: number[]): number[] {
hash.update(Buffer.from(bytesArray));
return Array.from(hash.digest()).map(x => (x < 128 ? x : x - 256));
}
function bytesToBigDecimal(arr: number[]): string {
let result = BigInt(0);
for (let i = 0; i < arr.length; i++) {
result = result * BigInt(256) + BigInt(arr[i] & 0xff);
}
return result.toString();
}
function hexToDecimal(hex: string): string {
return BigInt(`0x${hex}`).toString();
}

View File

@@ -89,8 +89,8 @@ export function parsePubKeyString(pubKeyString: string) {
const modulus = modulusMatch ? modulusMatch[1] : null;
const exponent = publicExponentMatch ? publicExponentMatch[1] : null;
console.log('Modulus:', modulus);
console.log('Public Exponent:', exponent);
// console.log('Modulus:', modulus);
// console.log('Public Exponent:', exponent);
if (!modulus || !exponent) {
throw new Error('Could not parse public key string');