Created
January 16, 2021 12:58
-
-
Save JackyYin/34c116bbe7bb4fc1de1ddec2b5f9d84d to your computer and use it in GitHub Desktop.
test size limit of RSA message body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bits = 2048 | |
const { publicKey } = crypto.generateKeyPairSync('rsa', { | |
modulusLength: bits, | |
publicKeyEncoding: { | |
type: 'pkcs1', | |
format: 'pem' | |
} | |
}) | |
const test = (len) => { | |
console.log(len) | |
try { | |
const buf = crypto.randomBytes(len) | |
crypto.publicEncrypt(publicKey, buf) | |
} catch (err) { | |
console.error(err) | |
test(--len) | |
} | |
} | |
test(bits / 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment