Skip to content

Commit

Permalink
pad cipher text post error
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed May 2, 2024
1 parent 37f69ca commit b55aaba
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ export async function decryptNodeData(eciesData: EciesHex, ciphertextHex: string
}

export async function decryptNodeDataWithPadding(eciesData: EciesHex, ciphertextHex: string, privKey: Buffer): Promise<Buffer> {
const ciphertextHexPadding = ciphertextHex.padStart(64, "0");
const metadata = encParamsHexToBuf(eciesData);

try {
const decryptedSigBuffer = await decrypt(privKey, {
...metadata,
ciphertext: Buffer.from(ciphertextHexPadding, "hex"),
ciphertext: Buffer.from(ciphertextHex, "hex"),
});
return decryptedSigBuffer;
} catch (error) {
const ciphertextHexPadding = ciphertextHex.padStart(64, "0");

log.warn("Failed to decrypt padded share cipher", error);
// try without cipher text padding
return decrypt(privKey, { ...metadata, ciphertext: Buffer.from(ciphertextHex, "hex") });
return decrypt(privKey, { ...metadata, ciphertext: Buffer.from(ciphertextHexPadding, "hex") });
}
}

Expand Down

0 comments on commit b55aaba

Please sign in to comment.