Skip to content

Instantly share code, notes, and snippets.

@JackyYin
Created January 16, 2021 12:58
Show Gist options
  • Save JackyYin/34c116bbe7bb4fc1de1ddec2b5f9d84d to your computer and use it in GitHub Desktop.
Save JackyYin/34c116bbe7bb4fc1de1ddec2b5f9d84d to your computer and use it in GitHub Desktop.
test size limit of RSA message body
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