Skip to content

Commit 0d43df8

Browse files
committed
fix: handle padding issue
1 parent a32d6d9 commit 0d43df8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/nobleEncryption.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ export const nobleDecrypt = async function (privateKey: Uint8Array, opts: NobleE
9292
const { iv, ephemPublicKey, ciphertext, mac } = opts;
9393
const sharedSecret = getSharedSecret(privateKey, ephemPublicKey);
9494
// need to remove first byte
95-
const sharedSecretSliced = sharedSecret.slice(1);
95+
let sharedSecretSliced = sharedSecret.slice(1);
96+
97+
if (!padding) {
98+
while (sharedSecretSliced.at(0) === 0) {
99+
sharedSecretSliced = sharedSecretSliced.slice(1);
100+
}
101+
}
96102

97103
const hash = sha512(sharedSecretSliced);
98104
const key = hash.slice(0, 32);

0 commit comments

Comments
 (0)