Hello,
Using this testcase from Google Wycheproof:
{
"algorithm" : "RSAES-PKCS1-v1_5",
"generatorVersion" : "0.8r12",
"numberOfTests" : 65,
"header" : [
"Test vectors of type RsaesPkcs1Decrypt are intended to check the decryption",
"of RSA encrypted ciphertexts."
],
"notes" : {
"InvalidPkcs1Padding" : "This is a test vector with an invalid PKCS #1 padding. Implementations must ensure that different error conditions cannot be distinguished, since the information about the error condition can be used for a padding oracle attack. (RFC 8017 Section 7.2.2)"
},
"schema" : "rsaes_pkcs1_decrypt_schema.json",
"testGroups" : [
{
"d" : "1a502d0eea6c7b69e21d5839101f705456ed0ef852fb47fe21071f54c5f33c8ceb066c62d727e32d26c58137329f89d3195325b795264c195d85472f7507dbd0961d2951f935a26b34f0ac24d15490e1128a9b7138915bc7dbfa8fe396357131c543ae9c98507368d9ceb08c1c6198a3eda7aea185a0e976cd42c22d00f003d9f19d96ea4c9afcbfe1441ccc802cfb0689f59d804c6a4e4f404c15174745ed6cb8bc88ef0b33ba0d2a80e35e43bc90f350052e72016e75b00d357a381c9c0d467069ca660887c987766349fcc43460b4aa516bce079edd87ba164307b752c277ed9528ad3ba0bf1877349ed3b7966a6c240110409bf4d0fade0c68fdadd847fd",
"e" : "010001",
"keysize" : 2048,
"n" : "00b3510a2bcd4ce644c5b594ae5059e12b2f054b658d5da5959a2fdf1871b808bc3df3e628d2792e51aad5c124b43bda453dca5cde4bcf28e7bd4effba0cb4b742bbb6d5a013cb63d1aa3a89e02627ef5398b52c0cfd97d208abeb8d7c9bce0bbeb019a86ddb589beb29a5b74bf861075c677c81d430f030c265247af9d3c9140ccb65309d07e0adc1efd15cf17e7b055d7da3868e4648cc3a180f0ee7f8e1e7b18098a3391b4ce7161e98d57af8a947e201a463e2d6bbca8059e5706e9dfed8f4856465ffa712ed1aa18e888d12dc6aa09ce95ecfca83cc5b0b15db09c8647f5d524c0f2e7620a3416b9623cadc0f097af573261c98c8400aa12af38e43cad84d",
"privateKeyJwk" : {
"alg" : "RSA1_5",
"d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+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----",
"privateKeyPkcs8" : "308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b3510a2bcd4ce644c5b594ae5059e12b2f054b658d5da5959a2fdf1871b808bc3df3e628d2792e51aad5c124b43bda453dca5cde4bcf28e7bd4effba0cb4b742bbb6d5a013cb63d1aa3a89e02627ef5398b52c0cfd97d208abeb8d7c9bce0bbeb019a86ddb589beb29a5b74bf861075c677c81d430f030c265247af9d3c9140ccb65309d07e0adc1efd15cf17e7b055d7da3868e4648cc3a180f0ee7f8e1e7b18098a3391b4ce7161e98d57af8a947e201a463e2d6bbca8059e5706e9dfed8f4856465ffa712ed1aa18e888d12dc6aa09ce95ecfca83cc5b0b15db09c8647f5d524c0f2e7620a3416b9623cadc0f097af573261c98c8400aa12af38e43cad84d0203010001028201001a502d0eea6c7b69e21d5839101f705456ed0ef852fb47fe21071f54c5f33c8ceb066c62d727e32d26c58137329f89d3195325b795264c195d85472f7507dbd0961d2951f935a26b34f0ac24d15490e1128a9b7138915bc7dbfa8fe396357131c543ae9c98507368d9ceb08c1c6198a3eda7aea185a0e976cd42c22d00f003d9f19d96ea4c9afcbfe1441ccc802cfb0689f59d804c6a4e4f404c15174745ed6cb8bc88ef0b33ba0d2a80e35e43bc90f350052e72016e75b00d357a381c9c0d467069ca660887c987766349fcc43460b4aa516bce079edd87ba164307b752c277ed9528ad3ba0bf1877349ed3b7966a6c240110409bf4d0fade0c68fdadd847fd02818100ec125cf37e310a2ff46263b9b2e0629d6390005ec88913d4fb71bd4dd856124498aaeba983d7ba2bd942e64d223feb7a23af4d605efeea6bd70d39afe99d35a3aa15e74a1768778093be0edd4a8d09b2def6dc9b67ff85764625c2e19236db4c401ce30a2572d3ecb4f969b7ad19c522c02d774465676e1a3776c54d6248348b02818100c2742abcd9897bd4b0b671f973fc82a8f84abf5705ff88dd41948623afe9dca60dc6543390767feaebeb539576ee8bfa61b5fcbca94a7cef75a09150c540fa9694dd8004ad23718c889049219369c99f4458d4afc148f6f07df87324a96d9cf7b385dd8622414a1832f9f29446f050c2d5a6407649dc41ab70e23b3dcc22c9870281810096a9798d250263400bb6277342881627e07cecdf91187b01b89ff47314188a7c20fb24800156d2c85d5666e8df6ceff9f9804ddfad80ff5767de56ecc029c72bf6c717df9f64daafc29acf9dc7908f9a0ad67e20e8949936ccba18d021a2c4febb04349a2b2047c4901385b6e5d0c691d118b33f81802b32ac272ef09e42fad50281800554f41b0b87f68a45722b3be0cf4ab1e165034c1a91002ab8f29e9ef9e2dab6fee7b2455bafb42037e9d2f7e533f348a147412fd72080be7c2633f5d802c91c39e6bcece3e675e59995033c55737020dad9e8b30d04b828adfb9304ad54a11a35a4f50709876ac5b118236ba76a4d7c9a291dd9607b169de1d182385691999f0281801c640189d9bfe8c623833210a76c420c6f44e5d760e259916cec2ae2b156456960fd95e2747660c389562250f055049cfab7e5c3039549384a7a2aaeb1c824d3af709482a8cf9b587022a00b1f0722db50f33cb26dc20dd2245d5265df61ee2983c938c2167dcee121fc4b4479c237e728cf633ab60a8c0ecd04fce7e3baa559",
"type" : "RsaesPkcs1Decrypt",
{ "tcId" : 31,
"comment" : "prepended bytes to ciphertext",
"msg" : "54657374",
"ct" : "00004501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d",
"result" : "invalid",
"flags" : []
},
I found that python-rsa (I'm using python-rsa 4.0) does not detect if bytes "0" have been prepended to the ciphertext using 2048, 3072 and 4096 bit keys and it decrypts the ciphertext without error. However, python-rsa detects if bytes "0" have been appended to the ciphertext and does not decrypt the ciphertext.
You can see this behaviour with 2048, 3072 and 4096 bit keys and the testvectors from Google Wycheproof below:
2048-bit test vector:
import rsa
from rsa import PrivateKey
import json
"""
{
"algorithm" : "RSAES-PKCS1-v1_5",
"generatorVersion" : "0.8r12",
"numberOfTests" : 65,
"header" : [
"Test vectors of type RsaesPkcs1Decrypt are intended to check the decryption",
"of RSA encrypted ciphertexts."
],
"notes" : {
"InvalidPkcs1Padding" : "This is a test vector with an invalid PKCS #1 padding. Implementations must ensure that different error conditions cannot be distinguished, since the information about the error condition can be used for a padding oracle attack. (RFC 8017 Section 7.2.2)"
},
"schema" : "rsaes_pkcs1_decrypt_schema.json",
"testGroups" : [
{
"d" : "1a502d0eea6c7b69e21d5839101f705456ed0ef852fb47fe21071f54c5f33c8ceb066c62d727e32d26c58137329f89d3195325b795264c195d85472f7507dbd0961d2951f935a26b34f0ac24d15490e1128a9b7138915bc7dbfa8fe396357131c543ae9c98507368d9ceb08c1c6198a3eda7aea185a0e976cd42c22d00f003d9f19d96ea4c9afcbfe1441ccc802cfb0689f59d804c6a4e4f404c15174745ed6cb8bc88ef0b33ba0d2a80e35e43bc90f350052e72016e75b00d357a381c9c0d467069ca660887c987766349fcc43460b4aa516bce079edd87ba164307b752c277ed9528ad3ba0bf1877349ed3b7966a6c240110409bf4d0fade0c68fdadd847fd",
"e" : "010001",
"keysize" : 2048,
"n" : "00b3510a2bcd4ce644c5b594ae5059e12b2f054b658d5da5959a2fdf1871b808bc3df3e628d2792e51aad5c124b43bda453dca5cde4bcf28e7bd4effba0cb4b742bbb6d5a013cb63d1aa3a89e02627ef5398b52c0cfd97d208abeb8d7c9bce0bbeb019a86ddb589beb29a5b74bf861075c677c81d430f030c265247af9d3c9140ccb65309d07e0adc1efd15cf17e7b055d7da3868e4648cc3a180f0ee7f8e1e7b18098a3391b4ce7161e98d57af8a947e201a463e2d6bbca8059e5706e9dfed8f4856465ffa712ed1aa18e888d12dc6aa09ce95ecfca83cc5b0b15db09c8647f5d524c0f2e7620a3416b9623cadc0f097af573261c98c8400aa12af38e43cad84d",
"privateKeyJwk" : {
"alg" : "RSA1_5",
"d" : "GlAtDupse2niHVg5EB9wVFbtDvhS-0f-IQcfVMXzPIzrBmxi1yfjLSbFgTcyn4nTGVMlt5UmTBldhUcvdQfb0JYdKVH5NaJrNPCsJNFUkOESiptxOJFbx9v6j-OWNXExxUOunJhQc2jZzrCMHGGYo-2nrqGFoOl2zULCLQDwA9nxnZbqTJr8v-FEHMyALPsGifWdgExqTk9ATBUXR0XtbLi8iO8LM7oNKoDjXkO8kPNQBS5yAW51sA01ejgcnA1GcGnKZgiHyYd2Y0n8xDRgtKpRa84Hnt2HuhZDB7dSwnftlSitO6C_GHc0ntO3lmpsJAEQQJv00PreDGj9rdhH_Q",
"dp" : "lql5jSUCY0ALtidzQogWJ-B87N-RGHsBuJ_0cxQYinwg-ySAAVbSyF1WZujfbO_5-YBN362A_1dn3lbswCnHK_bHF9-fZNqvwprPnceQj5oK1n4g6JSZNsy6GNAhosT-uwQ0misgR8SQE4W25dDGkdEYsz-BgCsyrCcu8J5C-tU",
"dq" : "BVT0GwuH9opFcis74M9KseFlA0wakQAquPKenvni2rb-57JFW6-0IDfp0vflM_NIoUdBL9cggL58JjP12ALJHDnmvOzj5nXlmZUDPFVzcCDa2eizDQS4KK37kwStVKEaNaT1BwmHasWxGCNrp2pNfJopHdlgexad4dGCOFaRmZ8",
"e" : "AQAB",
"kid" : "none",
"kty" : "RSA",
"n" : "s1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi_fGHG4CLw98-Yo0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv-6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM_ZfSCKvrjXybzgu-sBm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ihR0Ev1yCAvnwmM/XYAskcOea87OPmdeWZlQM8\nVXNwINrZ6LMNBLgorfuTBK1UoRo1pPUHCYdqxbEYI2unak18mikd2WB7Fp3h0YI4\nVpGZnwKBgBxkAYnZv+jGI4MyEKdsQgxvROXXYOJZkWzsKuKxVkVpYP2V4nR2YMOJ\nViJQ8FUEnPq35cMDlUk4SnoqrrHIJNOvcJSCqM+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----",
"privateKeyPkcs8" : "308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b3510a2bcd4ce644c5b594ae5059e12b2f054b658d5da5959a2fdf1871b808bc3df3e628d2792e51aad5c124b43bda453dca5cde4bcf28e7bd4effba0cb4b742bbb6d5a013cb63d1aa3a89e02627ef5398b52c0cfd97d208abeb8d7c9bce0bbeb019a86ddb589beb29a5b74bf861075c677c81d430f030c265247af9d3c9140ccb65309d07e0adc1efd15cf17e7b055d7da3868e4648cc3a180f0ee7f8e1e7b18098a3391b4ce7161e98d57af8a947e201a463e2d6bbca8059e5706e9dfed8f4856465ffa712ed1aa18e888d12dc6aa09ce95ecfca83cc5b0b15db09c8647f5d524c0f2e7620a3416b9623cadc0f097af573261c98c8400aa12af38e43cad84d0203010001028201001a502d0eea6c7b69e21d5839101f705456ed0ef852fb47fe21071f54c5f33c8ceb066c62d727e32d26c58137329f89d3195325b795264c195d85472f7507dbd0961d2951f935a26b34f0ac24d15490e1128a9b7138915bc7dbfa8fe396357131c543ae9c98507368d9ceb08c1c6198a3eda7aea185a0e976cd42c22d00f003d9f19d96ea4c9afcbfe1441ccc802cfb0689f59d804c6a4e4f404c15174745ed6cb8bc88ef0b33ba0d2a80e35e43bc90f350052e72016e75b00d357a381c9c0d467069ca660887c987766349fcc43460b4aa516bce079edd87ba164307b752c277ed9528ad3ba0bf1877349ed3b7966a6c240110409bf4d0fade0c68fdadd847fd02818100ec125cf37e310a2ff46263b9b2e0629d6390005ec88913d4fb71bd4dd856124498aaeba983d7ba2bd942e64d223feb7a23af4d605efeea6bd70d39afe99d35a3aa15e74a1768778093be0edd4a8d09b2def6dc9b67ff85764625c2e19236db4c401ce30a2572d3ecb4f969b7ad19c522c02d774465676e1a3776c54d6248348b02818100c2742abcd9897bd4b0b671f973fc82a8f84abf5705ff88dd41948623afe9dca60dc6543390767feaebeb539576ee8bfa61b5fcbca94a7cef75a09150c540fa9694dd8004ad23718c889049219369c99f4458d4afc148f6f07df87324a96d9cf7b385dd8622414a1832f9f29446f050c2d5a6407649dc41ab70e23b3dcc22c9870281810096a9798d250263400bb6277342881627e07cecdf91187b01b89ff47314188a7c20fb24800156d2c85d5666e8df6ceff9f9804ddfad80ff5767de56ecc029c72bf6c717df9f64daafc29acf9dc7908f9a0ad67e20e8949936ccba18d021a2c4febb04349a2b2047c4901385b6e5d0c691d118b33f81802b32ac272ef09e42fad50281800554f41b0b87f68a45722b3be0cf4ab1e165034c1a91002ab8f29e9ef9e2dab6fee7b2455bafb42037e9d2f7e533f348a147412fd72080be7c2633f5d802c91c39e6bcece3e675e59995033c55737020dad9e8b30d04b828adfb9304ad54a11a35a4f50709876ac5b118236ba76a4d7c9a291dd9607b169de1d182385691999f0281801c640189d9bfe8c623833210a76c420c6f44e5d760e259916cec2ae2b156456960fd95e2747660c389562250f055049cfab7e5c3039549384a7a2aaeb1c824d3af709482a8cf9b587022a00b1f0722db50f33cb26dc20dd2245d5265df61ee2983c938c2167dcee121fc4b4479c237e728cf633ab60a8c0ecd04fce7e3baa559",
"type" : "RsaesPkcs1Decrypt",
"""
"""
"tcId" : 31,
"comment" : "prepended bytes to ciphertext",
"msg" : "54657374",
"ct" : "00004501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d",
"result" : "invalid",
"flags" : []
},
"""
print("\nTest with prepended bytes to ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAs1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi/fGHG4CLw98+Yo\n0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv+6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM\n/ZfSCKvrjXybzgu+sBmobdtYm+sppbdL+GEHXGd8gdQw8DDCZSR6+dPJFAzLZTCd\nB+Ctwe/RXPF+ewVdfaOGjkZIzDoYDw7n+OHnsYCYozkbTOcWHpjVevipR+IBpGPi\n1rvKgFnlcG6d/tj0hWRl/6cS7RqhjoiNEtxqoJzpXs/Kg8xbCxXbCchkf11STA8u\ndiCjQWuWI8rcDwl69XMmHJjIQAqhKvOOQ8rYTQIDAQABAoIBABpQLQ7qbHtp4h1Y\nORAfcFRW7Q74UvtH/iEHH1TF8zyM6wZsYtcn4y0mxYE3Mp+J0xlTJbeVJkwZXYVH\nL3UH29CWHSlR+TWiazTwrCTRVJDhEoqbcTiRW8fb+o/jljVxMcVDrpyYUHNo2c6w\njBxhmKPtp66hhaDpds1Cwi0A8APZ8Z2W6kya/L/hRBzMgCz7Bon1nYBMak5PQEwV\nF0dF7Wy4vIjvCzO6DSqA415DvJDzUAUucgFudbANNXo4HJwNRnBpymYIh8mHdmNJ\n/MQ0YLSqUWvOB57dh7oWQwe3UsJ37ZUorTugvxh3NJ7Tt5ZqbCQBEECb9ND63gxo\n/a3YR/0CgYEA7BJc834xCi/0YmO5suBinWOQAF7IiRPU+3G9TdhWEkSYquupg9e6\nK9lC5k0iP+t6I69NYF7+6mvXDTmv6Z01o6oV50oXaHeAk74O3UqNCbLe9tybZ/+F\ndkYlwuGSNttMQBzjCiVy0+y0+Wm3rRnFIsAtd0RlZ24aN3bFTWJINIsCgYEAwnQq\nvNmJe9SwtnH5c/yCqPhKv1cF/4jdQZSGI6/p3KYNxlQzkHZ/6uvrU5V27ov6YbX8\nvKlKfO91oJFQxUD6lpTdgAStI3GMiJBJIZNpyZ9EWNSvwUj28H34cySpbZz3s4Xd\nhiJBShgy+fKURvBQwtWmQHZJ3EGrcOI7PcwiyYcCgYEAlql5jSUCY0ALtidzQogW\nJ+B87N+RGHsBuJ/0cxQYinwg+ySAAVbSyF1WZujfbO/5+YBN362A/1dn3lbswCnH\nK/bHF9+fZNqvwprPnceQj5oK1n4g6JSZNsy6GNAhosT+uwQ0misgR8SQE4W25dDG\nkdEYsz+BgCsyrCcu8J5C+tUCgYAFVPQbC4f2ikVyKzvgz0qx4WUDTBqRACq48p6e\n+eLatv7nskVbr7QgN+nS9+Uz80ihR0Ev1yCAvnwmM/XYAskcOea87OPmdeWZlQM8\nVXNwINrZ6LMNBLgorfuTBK1UoRo1pPUHCYdqxbEYI2unak18mikd2WB7Fp3h0YI4\nVpGZnwKBgBxkAYnZv+jGI4MyEKdsQgxvROXXYOJZkWzsKuKxVkVpYP2V4nR2YMOJ\nViJQ8FUEnPq35cMDlUk4SnoqrrHIJNOvcJSCqM+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("00004501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
"""
{
"tcId" : 32,
"comment" : "appended bytes to ciphertext",
"msg" : "54657374",
"ct" : "4501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d0000",
"result" : "invalid",
"flags" : []
},
"""
print("\nTest with appended bytes to ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAs1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi/fGHG4CLw98+Yo\n0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv+6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM\n/ZfSCKvrjXybzgu+sBmobdtYm+sppbdL+GEHXGd8gdQw8DDCZSR6+dPJFAzLZTCd\nB+Ctwe/RXPF+ewVdfaOGjkZIzDoYDw7n+OHnsYCYozkbTOcWHpjVevipR+IB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Latv7nskVbr7QgN+nS9+Uz80ihR0Ev1yCAvnwmM/XYAskcOea87OPmdeWZlQM8\nVXNwINrZ6LMNBLgorfuTBK1UoRo1pPUHCYdqxbEYI2unak18mikd2WB7Fp3h0YI4\nVpGZnwKBgBxkAYnZv+jGI4MyEKdsQgxvROXXYOJZkWzsKuKxVkVpYP2V4nR2YMOJ\nViJQ8FUEnPq35cMDlUk4SnoqrrHIJNOvcJSCqM+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("4501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d0000")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
print("\nTest with original ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAs1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi/fGHG4CLw98+Yo\n0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv+6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM\n/ZfSCKvrjXybzgu+sBmobdtYm+sppbdL+GEHXGd8gdQw8DDCZSR6+dP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G\nkdEYsz+BgCsyrCcu8J5C+tUCgYAFVPQbC4f2ikVyKzvgz0qx4WUDTBqRACq48p6e\n+eLatv7nskVbr7QgN+nS9+Uz80ihR0Ev1yCAvnwmM/XYAskcOea87OPmdeWZlQM8\nVXNwINrZ6LMNBLgorfuTBK1UoRo1pPUHCYdqxbEYI2unak18mikd2WB7Fp3h0YI4\nVpGZnwKBgBxkAYnZv+jGI4MyEKdsQgxvROXXYOJZkWzsKuKxVkVpYP2V4nR2YMOJ\nViJQ8FUEnPq35cMDlUk4SnoqrrHIJNOvcJSCqM+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("4501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
3072-bit test vector:
import rsa
from rsa import PrivateKey
import json
"""
{
"algorithm" : "RSAES-PKCS1-v1_5",
"generatorVersion" : "0.8r12",
"numberOfTests" : 65,
"header" : [
"Test vectors of type RsaesPkcs1Decrypt are intended to check the decryption",
"of RSA encrypted ciphertexts."
],
"notes" : {
"InvalidPkcs1Padding" : "This is a test vector with an invalid PKCS #1 padding. Implementations must ensure that different error conditions cannot be distinguished, since the information about the error condition can be used for a padding oracle attack. (RFC 8017 Section 7.2.2)"
},
"schema" : "rsaes_pkcs1_decrypt_schema.json",
"testGroups" : [
{
"d" : "0501205bd17b88d0d6626dd0fec898a0fd7f68f8dddcc314f74d167c40495b958a87e4ed63202e6ac68f4f4f4b88e3ec7a07d85757a7458468b766aad9a40f77337855408b28d140e75c2e6b3604ea8907bbd7f8e9578c2400ae645d28e2deef8bf718e29cf12fccb92fef9869f43aee5bd6adc223848d169cd6c27c2766652766ff81993b3e015a553decee0ffdc1624f39f8d96b6ed5d95047c1570b59fa2eb3d688dd5e14acc9407b8094f18b4694244eb1adcd655d873f57ff9af6e4fec470be236baf3b20c2040ab360d759c8b4e618bf8bd4e0ec6698f1b72c7160ed0521c82b5176b60fb63503d0ae23f6e2fb7a609305b0af62150b921ac53f4de899666cb01db0c9d8b650753015c1b6e682e6bf38204e59f7409c3808c0e53f254935540a381a963c2c1a77c6f987f06a07a0572686ed22882dbc82e7823cec080a58d72b09d00cc1d245cf158ff49cc40599d3af719dc301b4aa7f5b03629ae853e9daabe284db86d5c41d0401143df2b4593ef4e3747209c523f5a7f80f02d011",
"e" : "010001",
"keysize" : 3072,
"n" : "00dc8f7880672f0cf9d63617a8a58bdd271a109badda0fa826f94b8a795526b6a49a80564ccaba8a9491a935a53edeae1d9a7b5463d9e2ef3ee0ce7bff5d4b6c8147b5c073c2f220515d531d55a36687a6de3c34775c2f15191ac0a742d7342228c8d910fe6bbca439539c485debcbd0ee0e4bae317503b83cee8100ac7bb4587467cbc4373c4bda2eedf7c41631e50922b580f5bce81d24b208cabcd2d75fcfe99f75b493dffc5c9bd990f7fc3bf2efe392fecae36f3e4ef4456c1b5de99cc7451733a910b6834b61ec29274d986be3752c350b13a327dabc08dfcf6565499ad26e853446633eadb2970ca95bcf6bf05ffdbc2a804378d76985a71f06f90979f9fef716c36aa625a45b5eedf50825a53e9d9435b23caab9e5c64d38fd3a767e185ad7727d6e15f9e9bab2f4184d6487695db9a2698c672b2e823410dbef1d93fe40c9d357ee9fc77f849de11363f583af8ccf5181ca1aeb944c422516cb401e950923e4bd881439fa1093c77582bfe1ac5993674700b6434339e0245315d86fcb",
"privateKeyJwk" : {
"alg" : "RSA1_5",
"d" : "BQEgW9F7iNDWYm3Q_siYoP1_aPjd3MMU900WfEBJW5WKh-TtYyAuasaPT09LiOPsegfYV1enRYRot2aq2aQPdzN4VUCLKNFA51wuazYE6okHu9f46VeMJACuZF0o4t7vi_cY4pzxL8y5L--YafQ67lvWrcIjhI0WnNbCfCdmZSdm_4GZOz4BWlU97O4P_cFiTzn42Wtu1dlQR8FXC1n6LrPWiN1eFKzJQHuAlPGLRpQkTrGtzWVdhz9X_5r25P7EcL4ja687IMIECrNg11nItOYYv4vU4OxmmPG3LHFg7QUhyCtRdrYPtjUD0K4j9uL7emCTBbCvYhULkhrFP03omWZssB2wydi2UHUwFcG25oLmvzggTln3QJw4CMDlPyVJNVQKOBqWPCwad8b5h_BqB6BXJobtIogtvILngjzsCApY1ysJ0AzB0kXPFY_0nMQFmdOvcZ3DAbSqf1sDYproU-naq-KE24bVxB0EARQ98rRZPvTjdHIJxSP1p_gPAtAR",
"dp" : "8b-0DNVlc5cay162WwzSv0UCIo8s7KWkXDdmEVHL_bCgooIztgD-cn_WunHp8eFeTVMmCWCQf-Ac4dYU6iILrMhRJUG3hmN9UfM1X9RCIq97Di7RHZRUtPcWUjSy6KYhiN_zye8hyhwW9wqDNhUHXKK5woZBOY_U9Y_PJlD3Uqpqdgy1hN2WnOyA4ctN_etr8au4BmGJK899wopeozCcis9_A56K9T8mfVF6NzfS3hqcoVj-8XH4vaHppvA7CRKx",
"dq" : "Pjwq6NNi3JKU4txx0gUPfd_Z6lTVwwKDZq9nvhoJzeev5y4nclPELatjK_CELKaY9gLZk9GG4pBMZ2q5Zsb6Oq3uxNVgAyr1sOrRAljgQS5frTGFXm3cHjdC2leECzFX6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Iq97Di7RHZRUtPcWUjSy6KYhiN/zye8hyhwW9wqDNhUH\nXKK5woZBOY/U9Y/PJlD3Uqpqdgy1hN2WnOyA4ctN/etr8au4BmGJK899wopeozCc\nis9/A56K9T8mfVF6NzfS3hqcoVj+8XH4vaHppvA7CRKxAoHAPjwq6NNi3JKU4txx\n0gUPfd/Z6lTVwwKDZq9nvhoJzeev5y4nclPELatjK/CELKaY9gLZk9GG4pBMZ2q5\nZsb6Oq3uxNVgAyr1sOrRAljgQS5frTGFXm3cHjdC2leECzFX6OlGut5vxv5F5X87\noKXECCXfVrx2HNptJpN1fEvTGNQUxSfLdBTjUdfEnYVk7TebwAhIBs7FCAbhyGco\nt80rYGISpDJnv2lNZFPcyec/W3mKSaQzHSY6IiIVS12DSkNJAoHAGMyXHpGG+GwU\nTRQM6rvJriLJTo2FdTVvtqSgM5ke8hC6+jmkzRq/qZszL96eVpVa8XlFmnI2pwC3\n/R2ICTkG9hMK58qXQtntDVxj5qnptD302LJhwS0sL5FIvAZp8WW4uIGHnD7VjUps\n1aPxGT6avSeEYJwB+5CUx8giUyrXrsKgiu6eJjCVrQQmRVy1kljH/Tcxyone4xgA\n0ZHtcklyHCUmZlDEbcv7rjBwYE0uAJkUouJpoBuvpb34u6McTztg\n-----END RSA PRIVATE KEY-----",
"privateKeyPkcs8" : "308206fd020100300d06092a864886f70d0101010500048206e7308206e30201000282018100dc8f7880672f0cf9d63617a8a58bdd271a109badda0fa826f94b8a795526b6a49a80564ccaba8a9491a935a53edeae1d9a7b5463d9e2ef3ee0ce7bff5d4b6c8147b5c073c2f220515d531d55a36687a6de3c34775c2f15191ac0a742d7342228c8d910fe6bbca439539c485debcbd0ee0e4bae317503b83cee8100ac7bb4587467cbc4373c4bda2eedf7c41631e50922b580f5bce81d24b208cabcd2d75fcfe99f75b493dffc5c9bd990f7fc3bf2efe392fecae36f3e4ef4456c1b5de99cc7451733a910b6834b61ec29274d986be3752c350b13a327dabc08dfcf6565499ad26e853446633eadb2970ca95bcf6bf05ffdbc2a804378d76985a71f06f90979f9fef716c36aa625a45b5eedf50825a53e9d9435b23caab9e5c64d38fd3a767e185ad7727d6e15f9e9bab2f4184d6487695db9a2698c672b2e823410dbef1d93fe40c9d357ee9fc77f849de11363f583af8ccf5181ca1aeb944c422516cb401e950923e4bd881439fa1093c77582bfe1ac5993674700b6434339e0245315d86fcb0203010001028201800501205bd17b88d0d6626dd0fec898a0fd7f68f8dddcc314f74d167c40495b958a87e4ed63202e6ac68f4f4f4b88e3ec7a07d85757a7458468b766aad9a40f77337855408b28d140e75c2e6b3604ea8907bbd7f8e9578c2400ae645d28e2deef8bf718e29cf12fccb92fef9869f43aee5bd6adc223848d169cd6c27c2766652766ff81993b3e015a553decee0ffdc1624f39f8d96b6ed5d95047c1570b59fa2eb3d688dd5e14acc9407b8094f18b4694244eb1adcd655d873f57ff9af6e4fec470be236baf3b20c2040ab360d759c8b4e618bf8bd4e0ec6698f1b72c7160ed0521c82b5176b60fb63503d0ae23f6e2fb7a609305b0af62150b921ac53f4de899666cb01db0c9d8b650753015c1b6e682e6bf38204e59f7409c3808c0e53f254935540a381a963c2c1a77c6f987f06a07a0572686ed22882dbc82e7823cec080a58d72b09d00cc1d245cf158ff49cc40599d3af719dc301b4aa7f5b03629ae853e9daabe284db86d5c41d0401143df2b4593ef4e3747209c523f5a7f80f02d0110281c100fec6a10bfc49b58a2c850eafebdb997649a95575a0c17631b011cb20d7a320232a815b9af6040d7bf23d267e5e06304c33e04c85e6d481442f010a9758ba08364a70035ef99e9c98eeb431505b2afb6779d1c91d0ea2fb0a65dc391e79ecda7d52fd7dd69923b25dfae448cace829ebaca6b3c8a3cb64a81800614434895778c20d629b125b69f42945f66b644f3840bcfa6fce361074256c50863ecca2ce756b4a9fb7e993d0f1fa48b2cc485b7eaa61405fbef150e7563c2150811767de0f90281c100dd9ec1cee6d8a971b166902c44a4f02ef37a62053b41288a1d873d399cbc9e7bd306ed906487da2f49bc1c1809c0d4d88106d6879518ed925feb66aad5ff3c2b83466c554ed97b96abef55b3b02314f50d0385a0a1d8a46ae03e8fce91b412120f0a10dc681570fa564b6873bacd997b616b2bd7733fb723ade23bc1089da32e509583436f1e3448b579fb21b240620d20458d08f0f995abacc0a398f0ab6a67c9f5bcf7e032fb1d668fe698d80327599ae3fdf3aaaab19baf17639443194be30281c100f1bfb40cd56573971acb5eb65b0cd2bf4502228f2ceca5a45c37661151cbfdb0a0a28233b600fe727fd6ba71e9f1e15e4d53260960907fe01ce1d614ea220bacc8512541b786637d51f3355fd44222af7b0e2ed11d9454b4f7165234b2e8a62188dff3c9ef21ca1c16f70a833615075ca2b9c28641398fd4f58fcf2650f752aa6a760cb584dd969cec80e1cb4dfdeb6bf1abb80661892bcf7dc28a5ea3309c8acf7f039e8af53f267d517a3737d2de1a9ca158fef171f8bda1e9a6f03b0912b10281c03e3c2ae8d362dc9294e2dc71d2050f7ddfd9ea54d5c3028366af67be1a09cde7afe72e277253c42dab632bf0842ca698f602d993d186e2904c676ab966c6fa3aadeec4d560032af5b0ead10258e0412e5fad31855e6ddc1e3742da57840b3157e8e946bade6fc6fe45e57f3ba0a5c40825df56bc761cda6d2693757c4bd318d414c527cb7414e351d7c49d8564ed379bc0084806cec50806e1c86728b7cd2b606212a43267bf694d6453dcc9e73f5b798a49a4331d263a2222154b5d834a43490281c018cc971e9186f86c144d140ceabbc9ae22c94e8d8575356fb6a4a033991ef210bafa39a4cd1abfa99b332fde9e56955af179459a7236a700b7fd1d88093906f6130ae7ca9742d9ed0d5c63e6a9e9b43df4d8b261c12d2c2f9148bc0669f165b8b881879c3ed58d4a6cd5a3f1193e9abd2784609c01fb9094c7c822532ad7aec2a08aee9e263095ad0426455cb59258c7fd3731ca89dee31800d191ed7249721c25266650c46dcbfbae3070604d2e009914a2e269a01bafa5bdf8bba31c4f3b60",
"type" : "RsaesPkcs1Decrypt",
{
"tcId" : 31,
"comment" : "prepended bytes to ciphertext",
"msg" : "54657374",
"ct" : "000063b63f6eb3fd2322a6c85ed16318932e83f32535b3ec2527fb41dcc865bc44690554467655034ad33aa0fa993788e80654ab0e0174f8dd238ad68c3bc194f390dd38d26408778774848c49a6a606e7fb1b3bfbf5f19db4d4d1ba2db43fefb9a9bac311f2e1fc1ab4f5ddc00a009b9dc435448f250a648b206fe764505805c9bed1729d5bfeaa4fddafc115d281703fab0e79726d5546fa698a45ca6e5e561b8c2964b2da01914f808a498ab77672eda3432ed9974f0a06d320ff87a4222899f893a6cb6abf13d7e56cce2ee7eae67fc26f2274b63ce8301c721d7195158b6c966b8d36e3cff0aec6f218b0fa6d8490493471ee0f08b840b6cdcbb73a164246864de0f35565bbebe51585819e42a425090479537ed67f98236415e6ad3ca81116beb91db802dfb3f9da733f86cb6fa90904c8a382afcbf6162f0d89ee04973f2d26659325f7f00a4ae9e800de6aa27b6c94b9d57791658eb0714b7cba5466ecfe44bd5803647c3825b58c37187311a8b11399f53a877c265da82493a90869e376",
"result" : "invalid",
"flags" : []
},
"""
print("\nTest with prepended bytes to ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIG4wIBAAKCAYEA3I94gGcvDPnWNheopYvdJxoQm63aD6gm+UuKeVUmtqSagFZM\nyrqKlJGpNaU+3q4dmntUY9ni7z7gznv/XUtsgUe1wHPC8iBRXVMdVaNmh6bePDR3\nXC8VGRrAp0LXNCIoyNkQ/mu8pDlTnEhd68vQ7g5LrjF1A7g87oEArHu0WHRny8Q3\nPEvaLu33xBYx5QkitYD1vOgdJLIIyrzS11/P6Z91tJPf/Fyb2ZD3/Dvy7+OS/srj\nbz5O9EVsG13pnMdFFzOpELaDS2HsKSdNmGvjdSw1CxOjJ9q8CN/PZWVJmtJuhTRG\nYz6tspcMqVvPa/Bf/bwqgEN412mFpx8G+Ql5+f73FsNqpiWkW17t9QglpT6dlDWy\nPKq55cZNOP06dn4YWtdyfW4V+em6svQYTWSHaV25ommMZysugjQQ2+8dk/5AydNX\n7p/Hf4Sd4RNj9YOvjM9Rgcoa65RMQiUWy0A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8\n9+Ay+x1mj+aY2AMnWZrj/fOqqrGbrxdjlEMZS+MCgcEA8b+0DNVlc5cay162WwzS\nv0UCIo8s7KWkXDdmEVHL/bCgooIztgD+cn/WunHp8eFeTVMmCWCQf+Ac4dYU6iIL\nrMhRJUG3hmN9UfM1X9RCIq97Di7RHZRUtPcWUjSy6KYhiN/zye8hyhwW9wqDNhUH\nXKK5woZBOY/U9Y/PJlD3Uqpqdgy1hN2WnOyA4ctN/etr8au4BmGJK899wopeozCc\nis9/A56K9T8mfVF6NzfS3hqcoVj+8XH4vaHppvA7CRKxAoHAPjwq6NNi3JKU4txx\n0gUPfd/Z6lTVwwKDZq9nvhoJzeev5y4nclPELatjK/CELKaY9gLZk9GG4pBMZ2q5\nZsb6Oq3uxNVgAyr1sOrRAljgQS5frTGFXm3cHjdC2leECzFX6OlGut5vxv5F5X87\noKXECCXfVrx2HNptJpN1fEvTGNQUxSfLdBTjUdfEnYVk7TebwAhIBs7FCAbhyGco\nt80rYGISpDJnv2lNZFPcyec/W3mKSaQzHSY6IiIVS12DSkNJAoHAGMyXHpGG+GwU\nTRQM6rvJriLJTo2FdTVvtqSgM5ke8hC6+jmkzRq/qZszL96eVpVa8XlFmnI2pwC3\n/R2ICTkG9hMK58qXQtntDVxj5qnptD302LJhwS0sL5FIvAZp8WW4uIGHnD7VjUps\n1aPxGT6avSeEYJwB+5CUx8giUyrXrsKgiu6eJjCVrQQmRVy1kljH/Tcxyone4xgA\n0ZHtcklyHCUmZlDEbcv7rjBwYE0uAJkUouJpoBuvpb34u6McTztg\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("000063b63f6eb3fd2322a6c85ed16318932e83f32535b3ec2527fb41dcc865bc44690554467655034ad33aa0fa993788e80654ab0e0174f8dd238ad68c3bc194f390dd38d26408778774848c49a6a606e7fb1b3bfbf5f19db4d4d1ba2db43fefb9a9bac311f2e1fc1ab4f5ddc00a009b9dc435448f250a648b206fe764505805c9bed1729d5bfeaa4fddafc115d281703fab0e79726d5546fa698a45ca6e5e561b8c2964b2da01914f808a498ab77672eda3432ed9974f0a06d320ff87a4222899f893a6cb6abf13d7e56cce2ee7eae67fc26f2274b63ce8301c721d7195158b6c966b8d36e3cff0aec6f218b0fa6d8490493471ee0f08b840b6cdcbb73a164246864de0f35565bbebe51585819e42a425090479537ed67f98236415e6ad3ca81116beb91db802dfb3f9da733f86cb6fa90904c8a382afcbf6162f0d89ee04973f2d26659325f7f00a4ae9e800de6aa27b6c94b9d57791658eb0714b7cba5466ecfe44bd5803647c3825b58c37187311a8b11399f53a877c265da82493a90869e376")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
print("\nTest with original ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIG4wIBAAKCAYEA3I94gGcvDPnWNheopYvdJxoQm63aD6gm+UuKeVUmtqSagFZM\nyrqKlJGpNaU+3q4dmntUY9ni7z7gznv/XUtsgUe1wHPC8iBRXVMdVaNmh6bePDR3\nXC8VGRrAp0LXNCIoyNkQ/mu8pDlTnEhd68vQ7g5LrjF1A7g87oEArHu0WHRny8Q3\nPEvaLu33xBYx5QkitYD1vOgdJLIIyrzS11/P6Z91tJPf/Fyb2ZD3/Dvy7+OS/srj\nbz5O9EVsG13pnMdFFzOpELaDS2HsKSdNmGvjdSw1CxOjJ9q8CN/PZWVJmtJuhTRG\nYz6tspcMqVvPa/Bf/bwqgEN412mFpx8G+Ql5+f73FsNqpiWkW17t9QglpT6dlDWy\nPKq55cZNOP06dn4YWtdyfW4V+em6svQYTWSHaV25ommMZysugjQQ2+8dk/5AydNX\n7p/Hf4Sd4RNj9YOvjM9Rgcoa65RMQiUWy0AelQkj5L2IFDn6EJPHdYK/4axZk2dH\nALZDQzngJFMV2G/LAgMBAAECggGABQEgW9F7iNDWYm3Q/siYoP1/aP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kXDdmEVHL/bCgooIztgD+cn/WunHp8eFeTVMmCWCQf+Ac4dYU6iIL\nrMhRJUG3hmN9UfM1X9RCIq97Di7RHZRUtPcWUjSy6KYhiN/zye8hyhwW9wqDNhUH\nXKK5woZBOY/U9Y/PJlD3Uqpqdgy1hN2WnOyA4ctN/etr8au4BmGJK899wopeozCc\nis9/A56K9T8mfVF6NzfS3hqcoVj+8XH4vaHppvA7CRKxAoHAPjwq6NNi3JKU4txx\n0gUPfd/Z6lTVwwKDZq9nvhoJzeev5y4nclPELatjK/CELKaY9gLZk9GG4pBMZ2q5\nZsb6Oq3uxNVgAyr1sOrRAljgQS5frTGFXm3cHjdC2leECzFX6OlGut5vxv5F5X87\noKXECCXfVrx2HNptJpN1fEvTGNQUxSfLdBTjUdfEnYVk7TebwAhIBs7FCAbhyGco\nt80rYGISpDJnv2lNZFPcyec/W3mKSaQzHSY6IiIVS12DSkNJAoHAGMyXHpGG+GwU\nTRQM6rvJriLJTo2FdTVvtqSgM5ke8hC6+jmkzRq/qZszL96eVpVa8XlFmnI2pwC3\n/R2ICTkG9hMK58qXQtntDVxj5qnptD302LJhwS0sL5FIvAZp8WW4uIGHnD7VjUps\n1aPxGT6avSeEYJwB+5CUx8giUyrXrsKgiu6eJjCVrQQmRVy1kljH/Tcxyone4xgA\n0ZHtcklyHCUmZlDEbcv7rjBwYE0uAJkUouJpoBuvpb34u6McTztg\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("63b63f6eb3fd2322a6c85ed16318932e83f32535b3ec2527fb41dcc865bc44690554467655034ad33aa0fa993788e80654ab0e0174f8dd238ad68c3bc194f390dd38d26408778774848c49a6a606e7fb1b3bfbf5f19db4d4d1ba2db43fefb9a9bac311f2e1fc1ab4f5ddc00a009b9dc435448f250a648b206fe764505805c9bed1729d5bfeaa4fddafc115d281703fab0e79726d5546fa698a45ca6e5e561b8c2964b2da01914f808a498ab77672eda3432ed9974f0a06d320ff87a4222899f893a6cb6abf13d7e56cce2ee7eae67fc26f2274b63ce8301c721d7195158b6c966b8d36e3cff0aec6f218b0fa6d8490493471ee0f08b840b6cdcbb73a164246864de0f35565bbebe51585819e42a425090479537ed67f98236415e6ad3ca81116beb91db802dfb3f9da733f86cb6fa90904c8a382afcbf6162f0d89ee04973f2d26659325f7f00a4ae9e800de6aa27b6c94b9d57791658eb0714b7cba5466ecfe44bd5803647c3825b58c37187311a8b11399f53a877c265da82493a90869e376")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
4096-bit test vector:
import rsa
from rsa import PrivateKey
import json
"""
{
"algorithm" : "RSAES-PKCS1-v1_5",
"generatorVersion" : "0.8r12",
"numberOfTests" : 65,
"header" : [
"Test vectors of type RsaesPkcs1Decrypt are intended to check the decryption",
"of RSA encrypted ciphertexts."
],
"notes" : {
"InvalidPkcs1Padding" : "This is a test vector with an invalid PKCS #1 padding. Implementations must ensure that different error conditions cannot be distinguished, since the information about the error condition can be used for a padding oracle attack. (RFC 8017 Section 7.2.2)"
},
"schema" : "rsaes_pkcs1_decrypt_schema.json",
"testGroups" : [
{
"d" : "00d3519bd86edf5dbe9c64a3781713dd049b747f5651fd918cce8a9b80b6d6a2fb6aab334ab569a89b58982e0aae373090299fa227f9652b802d23ee5ca6824c433d01d40bb0473b16190a8bfb137c0a704b4f49b45015bfbee1f670446f07595259d70c7d79ae95f9b2543b0162ebb763ebb81c4b6edff9d197dede1dbe57e40466d156d4dfd5d7634c45534fb2bbbd1bf257817a173c0795fdbcc533976f4a0d04160f299af5dc272a814b36d5bae5116b9542178f1d554cab7a6453035482b981add4bd8ffd5d500839b23e30ebd3f3868f07584cbd12ba089325982860f69f2bdc7077b6c60f58a2272823379e1023704165f7c14f64a18fd5b245a18149b7eda3385a56ba9e79502a27bf13865cde35be15de03d06aa6f08b172b7eeb4b73cbc157019c5d933584a8d1add61b7dbca3b253ca0cf93dc9a8a3aac2f50227022e692f7b4767556620cc928d63e31078c360e2ab4b71a917e19e7eb09380482e5b4ea88202871c2a29ca6f66b2fe304af609520e4f81d64c26768bb812a86679366611f4cf6e89e2bd1d9d7e28729c7f0e4e3152d7ad7f186fa32f01e169ff06a12001bc179dfd0dc942cbabc555f67f5fd043e0a3354340fa490d2f123367be926eb3e1dffe70c3151c87450f3217dc2aa0b5a7069c5a17d55614c9994139f7b37b49e9fe780af65a0e89e2e58feaaffe163bc9d19eafd9cd29b0ef3cef3d01",
"e" : "010001",
"keysize" : 4096,
"n" : "00f601be0dccd04aa40b12f3f191ae17c1f9c8c0b68e7a77e14be25c3c7907cb1d33a6ef418ef41852f32c98392bc5c9aed91c1a1501c503eab89b3ee6f4f8eb2e0fcfc41bd03609cf6a8eb3aa6f0fbe23187b33db4d34b66d128a8aba0a2abf40bb9d13d8e2554569a57ab1d8c61b8cad2dc88599ae0da5346e15dace1bac7bf69737c22f083be9b46bb8b1eab5957b2da740275e96c87195b96fe11452159dafcfd916cee5d749a77bc3905a5ebd387ae445e8fe70f16e9a086639779ceffbfd41557bd99aea6a371a6b4b160615a1a12bc6958d34bce0c85adcbd8392fa10ceca52209d56196ba3d273ce228f1f111192aa92de2a039798a17bcecb4dc6100e6f8ae8c2643f2ae768b2255f082c978e95ca551555f10608231cf8003bbf807969fff1e51914b9a8c9b8f4564645b9e5d705ffad29663f5dae3d76652b422e43f13e6c1491090805c2d1268a74a251177427e33a9a91175c3670b91746008bce1fd231e6e4f2ad70cb43aca5f07600a6d31dd02915243dfdd943a02165da367a6b7e4dae1dd2e8b836903080795d2585076cc1c15dd9e8d2e5e047526569b1bfd395d957eb9fde325d342d14426e71efdc1887515e53cdea5834921f928629e748eed097ac4024e2bf255d70411f87373948cf8e8aa7effa2b0ab47d5166091e1aedec60568b155bd9c27bc55f3ece35f83d636dbcd5abf4853a051db94d5045",
"privateKeyJwk" : {
"alg" : "RSA1_5",
"d" : "01Gb2G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944020100300d06092a864886f70d01010105000482092e3082092a0201000282020100f601be0dccd04aa40b12f3f191ae17c1f9c8c0b68e7a77e14be25c3c7907cb1d33a6ef418ef41852f32c98392bc5c9aed91c1a1501c503eab89b3ee6f4f8eb2e0fcfc41bd03609cf6a8eb3aa6f0fbe23187b33db4d34b66d128a8aba0a2abf40bb9d13d8e2554569a57ab1d8c61b8cad2dc88599ae0da5346e15dace1bac7bf69737c22f083be9b46bb8b1eab5957b2da740275e96c87195b96fe11452159dafcfd916cee5d749a77bc3905a5ebd387ae445e8fe70f16e9a086639779ceffbfd41557bd99aea6a371a6b4b160615a1a12bc6958d34bce0c85adcbd8392fa10ceca52209d56196ba3d273ce228f1f111192aa92de2a039798a17bcecb4dc6100e6f8ae8c2643f2ae768b2255f082c978e95ca551555f10608231cf8003bbf807969fff1e51914b9a8c9b8f4564645b9e5d705ffad29663f5dae3d76652b422e43f13e6c1491090805c2d1268a74a251177427e33a9a91175c3670b91746008bce1fd231e6e4f2ad70cb43aca5f07600a6d31dd02915243dfdd943a02165da367a6b7e4dae1dd2e8b836903080795d2585076cc1c15dd9e8d2e5e047526569b1bfd395d957eb9fde325d342d14426e71efdc1887515e53cdea5834921f928629e748eed097ac4024e2bf255d70411f87373948cf8e8aa7effa2b0ab47d5166091e1aedec60568b155bd9c27bc55f3ece35f83d636dbcd5abf4853a051db94d504502030100010282020100d3519bd86edf5dbe9c64a3781713dd049b747f5651fd918cce8a9b80b6d6a2fb6aab334ab569a89b58982e0aae373090299fa227f9652b802d23ee5ca6824c433d01d40bb0473b16190a8bfb137c0a704b4f49b45015bfbee1f670446f07595259d70c7d79ae95f9b2543b0162ebb763ebb81c4b6edff9d197dede1dbe57e40466d156d4dfd5d7634c45534fb2bbbd1bf257817a173c0795fdbcc533976f4a0d04160f299af5dc272a814b36d5bae5116b9542178f1d554cab7a6453035482b981add4bd8ffd5d500839b23e30ebd3f3868f07584cbd12ba089325982860f69f2bdc7077b6c60f58a2272823379e1023704165f7c14f64a18fd5b245a18149b7eda3385a56ba9e79502a27bf13865cde35be15de03d06aa6f08b172b7eeb4b73cbc157019c5d933584a8d1add61b7dbca3b253ca0cf93dc9a8a3aac2f50227022e692f7b4767556620cc928d63e31078c360e2ab4b71a917e19e7eb09380482e5b4ea88202871c2a29ca6f66b2fe304af609520e4f81d64c26768bb812a86679366611f4cf6e89e2bd1d9d7e28729c7f0e4e3152d7ad7f186fa32f01e169ff06a12001bc179dfd0dc942cbabc555f67f5fd043e0a3354340fa490d2f123367be926eb3e1dffe70c3151c87450f3217dc2aa0b5a7069c5a17d55614c9994139f7b37b49e9fe780af65a0e89e2e58feaaffe163bc9d19eafd9cd29b0ef3cef3d010282010100fc21b855c5ad4ca2b6970516406f71c6e79efc4126e6598772db1e082de6b0dddaaa2a2951f04148e86e0bde28213b7f600f987308301eacea134062bb0c3ddf628da9abf93ef1ce3e75b0953a484dbd3554bd5c0649933dd77e527563e90f05a8013fddac958c329378e94303b304be5f9df1fe5b043a7fdd94700a3f0b1cbbd0516b7cd94c57ca96d9fd2a8ca973991218cba33a1c23d810f7519d1f7702ab72affdb3f84a1b2a88116e4033bc4d0cfc7989c657e0fe94e964476ae58bae6b7876f36c09d32b1a63f8c47c94a74c92eedf75fc27cffe0f8452363e4bc8f7653f3cb55eaf693cec70d13c875de935a8b20439ab7e93f76981c5957fc5bb44d90282010100f9c7f748a505d23ecef9a85f8097c8cf7d7028ef6c90e22a336511582d2cc3636e34ead37204dbd22f142a3fb1d5f857b0310c7a433f51ae14d4608b01b43aa8c7ae67835f7fbe0b9d97948b39e9ba2d3a1687edb8b56ee70ff0536dab4d0551f71ed0daee9e412449f5f099bcc15e4ef0554dc79f87fec5a0dea717c7054392bf444613937401bbef3c22fbf7e738c58779b981609a1f9c11dd6f0bbe9996e2773459e4cef247b02a9fc21296ac57a5b10561824310cfbdecc90e06598370e3698713fdbe2528ec4ef3dccaae701eedc3e54ad6e7af4e68e3b39bd2e97ac9119936c647a503511cb283df984cfd7c07f0f56aa8ae3166948ef3f41b0859934d0282010100815486aab0a0896bf97f13e3eb1f7f5c49195b49cc3b6277412a3688798b18f46422df479cb941b3b54e25964a3d69b897bcc8355160e58b4af29f1745dd2cabb670f634b9c058e6b3514947f2c27de5ed424f73b1e1f1be4a188911a0333f3a6688658b3ee8e3265a512e4deacadc470ee304ebb5224123afb461984fe8524fe0b6b30d32a59f6ed2dc74a96bc7cbfd1bb44e58a7092235c5d6272e12a2c862cb8c8cf5d109aa4fb1c6472875a14460c1ed5207c4b22bc494c7947eb7ca63a8cafd31361d000ddf16a2d79f13dd9140d979149b488cbf44945a5b6aaf13221bf4491ebbb7fca27ca20e221f49c3c37b89fcf2dc0e2cb63f8f8a9b7a142250590282010100b61d84ff934a4e437b16ee1b4b9fdf4ae13370b5385bde7a5464a123c0343df575f9e128ef9df944230d39cc9cf5dc0edb28b7e740b69ef024c1bfee39fcd5340ffaea0010160c535dc0920e7cd81be533d00fa554a1fc4d3e02c461569f5e7ca787f1515edf45b196b759884de652c38d5934cf92524e807b4d3b590bc39bc417ee4885a761d28ddadce6c8fdb3b961d3e7fd48064df9340a967f8b79997438841f48579a476ddb55088c308f68f2b29d01c6597a5a7c8d066284f63e37a68c3879c32aa3836675fd0eb2719883a91944561e9dd7e8aa6bb17157f08c48f8e6fae5c3e5a2bb6b5d580eec6c97ddcd9be0a49ef283a7031ad7aba8d438df4e950282010022fb8e5fcd9b767104e71244db53058c18061e1b0d1f63b73e2d59a95e2a10cd87426a33da13c287cdef8136e5e47e93fb9b30ad92628a7b543f48eb011a86356ab3cb480f27e391b018ca187d97af3d82e31861ecafa663db78aa89c3bd468e6aadefb3a43f78bc00b8014c95db54e9d21a017e8f21f671545edde9a965ea32dfff45cda37fca1aa5132f6c8eed222bd01fed5a6e7d639580c5955777a86544c2c4c939bdb8b4c486dda53072861a0334359bdb3758475e49d90d0539944e78cfcfd8fff55bb31a1cebc65b28f51e790701b2f7912188984f034e6e96e1c5251e33fe38fb221bce7a90a86857c5f56b6ca77307c45d5290b1f088ade082b349",
"type" : "RsaesPkcs1Decrypt",
{
"tcId" : 31,
"comment" : "prepended bytes to ciphertext",
"msg" : "54657374",
"ct" : "000004327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda",
"result" : "invalid",
"flags" : []
},
"""
print("\nTest with prepended bytes to ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIJKgIBAAKCAgEA9gG+DczQSqQLEvPxka4XwfnIwLaOenfhS+JcPHkHyx0zpu9B\njvQYUvMsmDkrxcmu2RwaFQHFA+q4mz7m9PjrLg/PxBvQNgnPao6zqm8PviMYezPb\nTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse/aXN8Iv\nCDvptGu4seq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TlinCSI1xdYn\nLhKiyGLLjIz10QmqT7HGRyh1oURgwe1SB8SyK8SUx5R+t8pjqMr9MTYdAA3fFqLX\nnxPdkUDZeRSbSIy/RJRaW2qvEyIb9Ekeu7f8onyiDiIfScPDe4n88twOLLY/j4qb\nehQiUFkCggEBALYdhP+TSk5DexbuG0uf30rhM3C1OFveelRkoSPAND31dfnhKO+d\n+UQjDTnMnPXcDtsot+dAtp7wJMG/7jn81TQP+uoAEBYMU13Akg582BvlM9APpVSh\n/E0+AsRhVp9efKeH8VFe30WxlrdZiE3mUsONWTTPklJOgHtNO1kLw5vEF+5Ihadh\n0o3a3ObI/bO5YdPn/UgGTfk0CpZ/i3mZdDiEH0hXmkdt21UIjDCPaPKynQHGWXpa\nfI0GYoT2PjemjDh5wyqjg2Z1/Q6ycZiDqRlEVh6d1+iqa7FxV/CMSPjm+uXD5aK7\na11YDuxsl93Nm+CknvKDpwMa16uo1DjfTpUCggEAIvuOX82bdnEE5xJE21MFjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("000004327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
print("\nTest with original ciphertext\n")
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIJKgIBAAKCAgEA9gG+DczQSqQLEvPxka4XwfnIwLaOenfhS+JcPHkHyx0zpu9B\njvQYUvMsmDkrxcmu2RwaFQHFA+q4mz7m9PjrLg/PxBvQNgnPao6zqm8PviMYezPb\nTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse/aXN8Iv\nCDvptGu4seq1lXstp0AnXpbIcZW5b+EUUhWdr8/ZFs7l10mne8OQWl69OHrkRej+\ncPFumghmOXec7/v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCd\nVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm+K6MJk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ALYdhP+TSk5DexbuG0uf30rhM3C1OFveelRkoSPAND31dfnhKO+d\n+UQjDTnMnPXcDtsot+dAtp7wJMG/7jn81TQP+uoAEBYMU13Akg582BvlM9APpVSh\n/E0+AsRhVp9efKeH8VFe30WxlrdZiE3mUsONWTTPklJOgHtNO1kLw5vEF+5Ihadh\n0o3a3ObI/bO5YdPn/UgGTfk0CpZ/i3mZdDiEH0hXmkdt21UIjDCPaPKynQHGWXpa\nfI0GYoT2PjemjDh5wyqjg2Z1/Q6ycZiDqRlEVh6d1+iqa7FxV/CMSPjm+uXD5aK7\na11YDuxsl93Nm+CknvKDpwMa16uo1DjfTpUCggEAIvuOX82bdnEE5xJE21MFjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')
ct = bytes.fromhex("04327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda")
pt = bytes.fromhex("54657374")
try:
message = rsa.decrypt(ct, private_key)
except:
print("[*] Invalid decryption")
else:
print("[!] No errors in decryption")
print("message == pt?", message == pt)
On the other hand, pcryptodome detects whenever bytes "0" are prepended to the ciphertext:
from Crypto.Cipher import PKCS1_v1_5
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
from Crypto.Hash import SHA
from Crypto import Random
privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAs1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi/fGHG4CLw98+Yo\n0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv+6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM\n/ZfSCKvrjXybzgu+sBmobdtYm+sppbdL+GEHXGd8gdQw8DDCZSR6+dPJFAzLZTCd\nB+Ctwe/RXPF+ewVdfaOGjkZIzDoYDw7n+OHnsYCYozkbTOcWHpjVevipR+IBpGPi\n1rvKgFnlcG6d/tj0hWRl/6cS7RqhjoiNEtxqoJzpXs/Kg8xbCxXbCchkf11STA8u\ndiCjQWuWI8rcDwl69XMmHJjIQAqhKvOOQ8rYTQIDAQABAoIBABpQLQ7qbHtp4h1Y\nORAfcFRW7Q74UvtH/i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vROXXYOJZkWzsKuKxVkVpYP2V4nR2YMOJ\nViJQ8FUEnPq35cMDlUk4SnoqrrHIJNOvcJSCqM+bWHAioAsfByLbUPM8sm3CDdIk\nXVJl32HuKYPJOMIWfc7hIfxLRHnCN+coz2M6tgqMDs0E/OfjuqVZ\n-----END RSA PRIVATE KEY-----"
private_key = RSA.importKey(privateKeyPem)
cipher = PKCS1_v1_5.new(private_key)
"""
"tcId" : 31,
"comment" : "prepended bytes to ciphertext",
"msg" : "54657374",
"ct" : "00004501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d",
"result" : "invalid",
"flags" : []
},
"""
ct = "4501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d"
print("[*] Unmodified ciphertext")
try:
secret = cipher.decrypt(bytes.fromhex(ct), "test")
print("\tDecryption OK")
except Exception as e:
print(e)
print("[*] Ciphertext with prepended bytes")
ct = "00004501b4d669e01b9ef2dc800aa1b06d49196f5a09fe8fbcd037323c60eaf027bfb98432be4e4a26c567ffec718bcbea977dd26812fa071c33808b4d5ebb742d9879806094b6fbeea63d25ea3141733b60e31c6912106e1b758a7fe0014f075193faa8b4622bfd5d3013f0a32190a95de61a3604711bc62945f95a6522bd4dfed0a994ef185b28c281f7b5e4c8ed41176d12d9fc1b837e6a0111d0132d08a6d6f0580de0c9eed8ed105531799482d1e466c68c23b0c222af7fc12ac279bc4ff57e7b4586d209371b38c4c1035edd418dc5f960441cb21ea2bedbfea86de0d7861e81021b650a1de51002c315f1e7c12debe4dcebf790caaa54a2f26b149cf9e77d"
try:
secret = cipher.decrypt(bytes.fromhex(ct), "test")
except Exception as e:
print("\t", e)
Best regards,
Antonio
bug critical