Python-RSA is a pure-Python RSA implementation.

Overview

Pure Python RSA implementation

PyPI Build Status Coverage Status Code Climate

Python-RSA is a pure-Python RSA implementation. It supports encryption and decryption, signing and verifying signatures, and key generation according to PKCS#1 version 1.5. It can be used as a Python library as well as on the commandline. The code was mostly written by Sybren A. Stüvel.

Documentation can be found at the Python-RSA homepage. For all changes, check the changelog.

Download and install using:

pip install rsa

or download it from the Python Package Index.

The source code is maintained at GitHub and is licensed under the Apache License, version 2.0

Security

Because of how Python internally stores numbers, it is very hard (if not impossible) to make a pure-Python program secure against timing attacks. This library is no exception, so use it with care. See https://securitypitfalls.wordpress.com/2018/08/03/constant-time-compare-in-python/ for more info.

Major changes in 4.1

Version 4.0 was the last version to support Python 2 and 3.4. Version 4.1 is compatible with Python 3.5+ only.

Major changes in 4.0

Version 3.4 was the last version in the 3.x range. Version 4.0 drops the following modules, as they are insecure:

  • rsa._version133
  • rsa._version200
  • rsa.bigfile
  • rsa.varblock

Those modules were marked as deprecated in version 3.4.

Furthermore, in 4.0 the I/O functions is streamlined to always work with bytes on all supported versions of Python.

Version 4.0 drops support for Python 2.6 and 3.3.

Comments
  • BytesWarning in rsa.PrivateKey.load_pkcs1

    BytesWarning in rsa.PrivateKey.load_pkcs1

    Running the code in the Generating keys documentation and enabling BytesWarnings with -bb results in a BytesWarning:

    import rsa
    
    
    with open('private.pem') as privatefile:
        keydata = privatefile.read()
    pubkey = rsa.PrivateKey.load_pkcs1(keydata)
    
    C:\Python35\python.exe -bb "C:/Users/John Hagen/PycharmProjects/test/a.py"
    Traceback (most recent call last):
      File "C:/Users/John Hagen/PycharmProjects/test/a.py", line 6, in <module>
        pubkey = rsa.PrivateKey.load_pkcs1(keydata)
      File "C:\Python35\lib\site-packages\rsa\key.py", line 75, in load_pkcs1
        return method(keyfile)
      File "C:\Python35\lib\site-packages\rsa\key.py", line 511, in _load_pkcs1_pem
        return cls._load_pkcs1_der(der)
      File "C:\Python35\lib\site-packages\rsa\key.py", line 439, in _load_pkcs1_der
        (priv, _) = decoder.decode(keyfile)
      File "C:\Python35\lib\site-packages\pyasn1\codec\ber\decoder.py", line 825, in __call__
        stGetValueDecoder, self, substrateFun
      File "C:\Python35\lib\site-packages\pyasn1\codec\ber\decoder.py", line 342, in valueDecoder
        component, head = decodeFun(head, asn1Spec)
      File "C:\Python35\lib\site-packages\pyasn1\codec\ber\decoder.py", line 825, in __call__
        stGetValueDecoder, self, substrateFun
      File "C:\Python35\lib\site-packages\pyasn1\codec\ber\decoder.py", line 95, in valueDecoder
        if head in self.precomputedValues:
    BytesWarning: Comparison between bytes and string
    

    Tested on using rsa 3.4.2 on Windows 10 with Python 3.5.2.

    minor waiting-for-upstream-release 
    opened by johnthagen 29
  • CVE-2020-25658 - Bleichenbacher-style timing oracle in PKCS#1 v1.5 decryption code

    CVE-2020-25658 - Bleichenbacher-style timing oracle in PKCS#1 v1.5 decryption code

    Current PKCS#1 v1.5 decryption code: https://github.com/sybrenstuvel/python-rsa/blob/6f59ff07a317409fe68696935daf8549b1555c74/rsa/pkcs1.py#L246-L267

    performs the checks on the decrypted value in turn, aborting as soon as first error is found, it also raises an exception in case of errors. This likely provides enough of a timing side channel to mount a Bleichenbacher style attack.

    While it's unlikely that a completely side-channel free implementation is possible (see https://securitypitfalls.wordpress.com/2018/08/03/constant-time-compare-in-python/ ), it should be possible to minimise the side-channel by making at least the execution path the same irrespective of previous checks and by providing an API that returns a randomly generated secret in case of error (instead of leaking the timing side-channel by rising an exception) for uses that decrypted value directly as an input to a hash or use it as a symmetric key.

    opened by tomato42 28
  • Possible bug introduced in 4.7

    Possible bug introduced in 4.7

    Hi! I am a a dvc user. This library connects to Google Cloud Storage, and it can use a google service key to authenticate. When authenticating in this way, the google-auth library fails with {"error":"invalid_grant","error_description":"Invalid JWT Signature."}. This happens with rsa==4.7 but not with with rsa==4.6. After some research, we found that restoring the 4.6 version of the rsa/key.py file solves the problem.

    opened by alvaroabascar 18
  • python-rsa does not detect ciphertext modification (prepended

    python-rsa does not detect ciphertext modification (prepended "0" bytes) in PKCS1_v1_5

    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" : "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-sBmobdtYm-sppbdL-GEHXGd8gdQw8DDCZSR6-dPJFAzLZTCdB-Ctwe_RXPF-ewVdfaOGjkZIzDoYDw7n-OHnsYCYozkbTOcWHpjVevipR-IBpGPi1rvKgFnlcG6d_tj0hWRl_6cS7RqhjoiNEtxqoJzpXs_Kg8xbCxXbCchkf11STA8udiCjQWuWI8rcDwl69XMmHJjIQAqhKvOOQ8rYTQ",
            "p" : "7BJc834xCi_0YmO5suBinWOQAF7IiRPU-3G9TdhWEkSYquupg9e6K9lC5k0iP-t6I69NYF7-6mvXDTmv6Z01o6oV50oXaHeAk74O3UqNCbLe9tybZ_-FdkYlwuGSNttMQBzjCiVy0-y0-Wm3rRnFIsAtd0RlZ24aN3bFTWJINIs",
            "q" : "wnQqvNmJe9SwtnH5c_yCqPhKv1cF_4jdQZSGI6_p3KYNxlQzkHZ_6uvrU5V27ov6YbX8vKlKfO91oJFQxUD6lpTdgAStI3GMiJBJIZNpyZ9EWNSvwUj28H34cySpbZz3s4XdhiJBShgy-fKURvBQwtWmQHZJ3EGrcOI7PcwiyYc",
            "qi" : "HGQBidm_6MYjgzIQp2xCDG9E5ddg4lmRbOwq4rFWRWlg_ZXidHZgw4lWIlDwVQSc-rflwwOVSThKeiquscgk069wlIKoz5tYcCKgCx8HIttQ8zyybcIN0iRdUmXfYe4pg8k4whZ9zuEh_EtEecI35yjPYzq2CowOzQT85-O6pVk"
          },
          "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/iEHH1TF8z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kWzsKuKxVkVpYP2V4nR2YMOJ\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" : []
    },
    

    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-sBmobdtYm-sppbdL-GEHXGd8gdQw8DDCZSR6-dPJFAzLZTCdB-Ctwe_RXPF-ewVdfaOGjkZIzDoYDw7n-OHnsYCYozkbTOcWHpjVevipR-IBpGPi1rvKgFnlcG6d_tj0hWRl_6cS7RqhjoiNEtxqoJzpXs_Kg8xbCxXbCchkf11STA8udiCjQWuWI8rcDwl69XMmHJjIQAqhKvOOQ8rYTQ",
            "p" : "7BJc834xCi_0YmO5suBinWOQAF7IiRPU-3G9TdhWEkSYquupg9e6K9lC5k0iP-t6I69NYF7-6mvXDTmv6Z01o6oV50oXaHeAk74O3UqNCbLe9tybZ_-FdkYlwuGSNttMQBzjCiVy0-y0-Wm3rRnFIsAtd0RlZ24aN3bFTWJINIs",
            "q" : "wnQqvNmJe9SwtnH5c_yCqPhKv1cF_4jdQZSGI6_p3KYNxlQzkHZ_6uvrU5V27ov6YbX8vKlKfO91oJFQxUD6lpTdgAStI3GMiJBJIZNpyZ9EWNSvwUj28H34cySpbZz3s4XdhiJBShgy-fKURvBQwtWmQHZJ3EGrcOI7PcwiyYc",
            "qi" : "HGQBidm_6MYjgzIQp2xCDG9E5ddg4lmRbOwq4rFWRWlg_ZXidHZgw4lWIlDwVQSc-rflwwOVSThKeiquscgk069wlIKoz5tYcCKgCx8HIttQ8zyybcIN0iRdUmXfYe4pg8k4whZ9zuEh_EtEecI35yjPYzq2CowOzQT85-O6pVk"
          },
          "privateKeyPem" : "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAs1EKK81M5kTFtZSuUFnhKy8FS2WNXaWVmi/fGHG4CLw98+Yo\n0nkuUarVwSS0O9pFPcpc3kvPKOe9Tv+6DLS3Qru21aATy2PRqjqJ4CYn71OYtSwM\n/ZfSCKvrjXybzgu+sBmobdtY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SZNsy6GNAhosT+uwQ0misgR8SQE4W25dDG\nkdEYsz+BgCsyrCcu8J5C+tUCgYAFVPQbC4f2ikVyKzvgz0qx4WUDTBqRACq48p6e\n+eLatv7nskVbr7QgN+nS9+Uz80ihR0Ev1yCAvnwmM/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\nF0dF7Wy4vIjvCz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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\n0nkuUarVwSS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J/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("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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34cySpbZz3s4Xd\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("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_CELKaY9gLZk9GG4pBMZ2q5Zsb6Oq3uxNVgAyr1sOrRAljgQS5frTGFXm3cHjdC2leECzFX6OlGut5vxv5F5X87oKXECCXfVrx2HNptJpN1fEvTGNQUxSfLdBTjUdfEnYVk7TebwAhIBs7FCAbhyGcot80rYGISpDJnv2lNZFPcyec_W3mKSaQzHSY6IiIVS12DSkNJ",
            "e" : "AQAB",
            "kid" : "none",
            "kty" : "RSA",
            "n" : "3I94gGcvDPnWNheopYvdJxoQm63aD6gm-UuKeVUmtqSagFZMyrqKlJGpNaU-3q4dmntUY9ni7z7gznv_XUtsgUe1wHPC8iBRXVMdVaNmh6bePDR3XC8VGRrAp0LXNCIoyNkQ_mu8pDlTnEhd68vQ7g5LrjF1A7g87oEArHu0WHRny8Q3PEvaLu33xBYx5QkitYD1vOgdJLIIyrzS11_P6Z91tJPf_Fyb2ZD3_Dvy7-OS_srjbz5O9EVsG13pnMdFFzOpELaDS2HsKSdNmGvjdSw1CxOjJ9q8CN_PZWVJmtJuhTRGYz6tspcMqVvPa_Bf_bwqgEN412mFpx8G-Ql5-f73FsNqpiWkW17t9QglpT6dlDWyPKq55cZNOP06dn4YWtdyfW4V-em6svQYTWSHaV25ommMZysugjQQ2-8dk_5AydNX7p_Hf4Sd4RNj9YOvjM9Rgcoa65RMQiUWy0AelQkj5L2IFDn6EJPHdYK_4axZk2dHALZDQzngJFMV2G_L",
            "p" : "_sahC_xJtYoshQ6v69uZdkmpVXWgwXYxsBHLINejICMqgVua9gQNe_I9Jn5eBjBMM-BMhebUgUQvAQqXWLoINkpwA175npyY7rQxUFsq-2d50ckdDqL7CmXcOR557Np9Uv191pkjsl365EjKzoKeusprPIo8tkqBgAYUQ0iVd4wg1imxJbafQpRfZrZE84QLz6b842EHQlbFCGPsyiznVrSp-36ZPQ8fpIssxIW36qYUBfvvFQ51Y8IVCBF2feD5",
            "q" : "3Z7BzubYqXGxZpAsRKTwLvN6YgU7QSiKHYc9OZy8nnvTBu2QZIfaL0m8HBgJwNTYgQbWh5UY7ZJf62aq1f88K4NGbFVO2XuWq-9Vs7AjFPUNA4WgodikauA-j86RtBISDwoQ3GgVcPpWS2hzus2Ze2FrK9dzP7cjreI7wQidoy5QlYNDbx40SLV5-yGyQGINIEWNCPD5lauswKOY8KtqZ8n1vPfgMvsdZo_mmNgDJ1ma4_3zqqqxm68XY5RDGUvj",
            "qi" : "GMyXHpGG-GwUTRQM6rvJriLJTo2FdTVvtqSgM5ke8hC6-jmkzRq_qZszL96eVpVa8XlFmnI2pwC3_R2ICTkG9hMK58qXQtntDVxj5qnptD302LJhwS0sL5FIvAZp8WW4uIGHnD7VjUps1aPxGT6avSeEYJwB-5CUx8giUyrXrsKgiu6eJjCVrQQmRVy1kljH_Tcxyone4xgA0ZHtcklyHCUmZlDEbcv7rjBwYE0uAJkUouJpoBuvpb34u6McTztg"
          },
          "privateKeyPem" : "-----BEGIN RSA PRIVATE KEY-----\nMIIG4wIBAAKCAYEA3I94gGcvDPnWNheopYvdJxoQm63aD6gm+UuKeVUmtqSagFZM\nyrqKlJGpNaU+3q4dmntUY9ni7z7gznv/XUtsgUe1wHPC8iBRXVMdVaNmh6bePDR3\nXC8VGRrAp0LXNCIoyNkQ/mu8pDlTnEhd68vQ7g5LrjF1A7g87oEArHu0WHRny8Q3\nPEvaLu33xBYx5QkitYD1vOgdJLIIyrzS11/P6Z91tJPf/Fyb2ZD3/Dvy7+OS/srj\nbz5O9EVsG13pnMdFFzOpELaDS2HsKSdNmGvjdSw1CxOjJ9q8CN/PZWVJmtJuhTRG\nYz6tspcMqVvPa/Bf/bwqgEN412mFpx8G+Ql5+f73FsNqpiWkW17t9Q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aCh2KRq4D6PzpG0EhIPChDcaBVw+lZLaHO6zZl7YWsr\n13M/tyOt4jvBCJ2jLlCVg0NvHjRItXn7IbJAYg0gRY0I8PmVq6zAo5jwq2pnyfW8\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-----",
          "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\nPEvaLu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one4xgA\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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-----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" : "01Gb2G7fXb6cZKN4FxPdBJt0f1ZR_ZGMzoqbgLbWovtqqzNKtWmom1iYLgquNzCQKZ-iJ_llK4AtI-5cpoJMQz0B1AuwRzsWGQqL-xN8CnBLT0m0UBW_vuH2cERvB1lSWdcMfXmulfmyVDsBYuu3Y-u4HEtu3_nRl97eHb5X5ARm0VbU39XXY0xFU0-yu70b8leBehc8B5X9vMUzl29KDQQWDyma9dwnKoFLNtW65RFrlUIXjx1VTKt6ZFMDVIK5ga3UvY_9XVAIObI-MOvT84aPB1hMvRK6CJMlmChg9p8r3HB3tsYPWKInKCM3nhAjcEFl98FPZKGP1bJFoYFJt-2jOFpWup55UConvxOGXN41vhXeA9BqpvCLFyt-60tzy8FXAZxdkzWEqNGt1ht9vKOyU8oM-T3JqKOqwvUCJwIuaS97R2dVZiDMko1j4xB4w2Diq0txqRfhnn6wk4BILltOqIIChxwqKcpvZrL-MEr2CVIOT4HWTCZ2i7gSqGZ5NmYR9M9uieK9HZ1-KHKcfw5OMVLXrX8Yb6MvAeFp_wahIAG8F539DclCy6vFVfZ_X9BD4KM1Q0D6SQ0vEjNnvpJus-Hf_nDDFRyHRQ8yF9wqoLWnBpxaF9VWFMmZQTn3s3tJ6f54CvZaDoni5Y_qr_4WO8nRnq_ZzSmw7zzvPQE",
            "dp" : "gVSGqrCgiWv5fxPj6x9_XEkZW0nMO2J3QSo2iHmLGPRkIt9HnLlBs7VOJZZKPWm4l7zINVFg5YtK8p8XRd0sq7Zw9jS5wFjms1FJR_LCfeXtQk9zseHxvkoYiRGgMz86Zohliz7o4yZaUS5N6srcRw7jBOu1IkEjr7RhmE_oUk_gtrMNMqWfbtLcdKlrx8v9G7ROWKcJIjXF1icuEqLIYsuMjPXRCapPscZHKHWhRGDB7VIHxLIrxJTHlH63ymOoyv0xNh0ADd8WotefE92RQNl5FJtIjL9ElFpbaq8TIhv0SR67t_yifKIOIh9Jw8N7ifzy3A4stj-Pipt6FCJQWQ",
            "dq" : "th2E_5NKTkN7Fu4bS5_fSuEzcLU4W956VGShI8A0PfV1-eEo7535RCMNOcyc9dwO2yi350C2nvAkwb_uOfzVNA_66gAQFgxTXcCSDnzYG-Uz0A-lVKH8TT4CxGFWn158p4fxUV7fRbGWt1mITeZSw41ZNM-SUk6Ae007WQvDm8QX7kiFp2HSjdrc5sj9s7lh0-f9SAZN-TQKln-LeZl0OIQfSFeaR23bVQiMMI9o8rKdAcZZelp8jQZihPY-N6aMOHnDKqODZnX9DrJxmIOpGURWHp3X6KprsXFX8IxI-Ob65cPlortrXVgO7GyX3c2b4KSe8oOnAxrXq6jUON9OlQ",
            "e" : "AQAB",
            "kid" : "none",
            "kty" : "RSA",
            "n" : "9gG-DczQSqQLEvPxka4XwfnIwLaOenfhS-JcPHkHyx0zpu9BjvQYUvMsmDkrxcmu2RwaFQHFA-q4mz7m9PjrLg_PxBvQNgnPao6zqm8PviMYezPbTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse_aXN8IvCDvptGu4seq1lXstp0AnXpbIcZW5b-EUUhWdr8_ZFs7l10mne8OQWl69OHrkRej-cPFumghmOXec7_v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCdVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm-K6MJkPyrnaLIlXw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FjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----",
          "privateKeyPkcs8" : "30820944020100300d06092a864886f70d01010105000482092e3082092a0201000282020100f601be0dccd04aa40b12f3f191ae17c1f9c8c0b68e7a77e14be25c3c7907cb1d33a6ef418ef41852f32c98392bc5c9aed91c1a1501c503eab89b3ee6f4f8eb2e0fcfc41bd03609cf6a8eb3aa6f0fbe23187b33db4d34b66d128a8aba0a2abf40bb9d13d8e2554569a57ab1d8c61b8cad2dc88599ae0da5346e15dace1bac7bf69737c22f083be9b46bb8b1eab5957b2da740275e96c87195b96fe11452159dafcfd916cee5d749a77bc3905a5ebd387ae445e8fe70f16e9a086639779ceffbfd41557bd99aea6a371a6b4b160615a1a12bc6958d34bce0c85adcbd8392fa10ceca52209d56196ba3d273ce228f1f111192aa92de2a039798a17bcecb4dc6100e6f8ae8c2643f2ae768b2255f082c978e95ca551555f10608231cf8003bbf807969fff1e51914b9a8c9b8f4564645b9e5d705ffad29663f5dae3d76652b422e43f13e6c1491090805c2d1268a74a251177427e33a9a91175c3670b91746008bce1fd231e6e4f2ad70cb43aca5f07600a6d31dd02915243dfdd943a02165da367a6b7e4dae1dd2e8b836903080795d2585076cc1c15dd9e8d2e5e047526569b1bfd395d957eb9fde325d342d14426e71efdc1887515e53cdea5834921f928629e748eed097ac4024e2bf255d70411f87373948cf8e8aa7effa2b0ab47d5166091e1aedec60568b155bd9c27bc55f3ece35f83d636dbcd5abf4853a051db94d504502030100010282020100d3519bd86edf5dbe9c64a3781713dd049b747f5651fd918cce8a9b80b6d6a2fb6aab334ab569a89b58982e0aae373090299fa227f9652b802d23ee5ca6824c433d01d40bb0473b16190a8bfb137c0a704b4f49b45015bfbee1f670446f07595259d70c7d79ae95f9b2543b0162ebb763ebb81c4b6edff9d197dede1dbe57e40466d156d4dfd5d7634c45534fb2bbbd1bf257817a173c0795fdbcc533976f4a0d04160f299af5dc272a814b36d5bae5116b9542178f1d554cab7a6453035482b981add4bd8ffd5d500839b23e30ebd3f3868f07584cbd12ba089325982860f69f2bdc7077b6c60f58a2272823379e1023704165f7c14f64a18fd5b245a18149b7eda3385a56ba9e79502a27bf13865cde35be15de03d06aa6f08b172b7eeb4b73cbc157019c5d933584a8d1add61b7dbca3b253ca0cf93dc9a8a3aac2f50227022e692f7b4767556620cc928d63e31078c360e2ab4b71a917e19e7eb09380482e5b4ea88202871c2a29ca6f66b2fe304af609520e4f81d64c26768bb812a86679366611f4cf6e89e2bd1d9d7e28729c7f0e4e3152d7ad7f186fa32f01e169ff06a12001bc179dfd0dc942cbabc555f67f5fd043e0a3354340fa490d2f123367be926eb3e1dffe70c3151c87450f3217dc2aa0b5a7069c5a17d55614c9994139f7b37b49e9fe780af65a0e89e2e58feaaffe163bc9d19eafd9cd29b0ef3cef3d010282010100fc21b855c5ad4ca2b6970516406f71c6e79efc4126e6598772db1e082de6b0dddaaa2a2951f04148e86e0bde28213b7f600f987308301eacea134062bb0c3ddf628da9abf93ef1ce3e75b0953a484dbd3554bd5c0649933dd77e527563e90f05a8013fddac958c329378e94303b304be5f9df1fe5b043a7fdd94700a3f0b1cbbd0516b7cd94c57ca96d9fd2a8ca973991218cba33a1c23d810f7519d1f7702ab72affdb3f84a1b2a88116e4033bc4d0cfc7989c657e0fe94e964476ae58bae6b7876f36c09d32b1a63f8c47c94a74c92eedf75fc27cffe0f8452363e4bc8f7653f3cb55eaf693cec70d13c875de935a8b20439ab7e93f76981c5957fc5bb44d90282010100f9c7f748a505d23ecef9a85f8097c8cf7d7028ef6c90e22a336511582d2cc3636e34ead37204dbd22f142a3fb1d5f857b0310c7a433f51ae14d4608b01b43aa8c7ae67835f7fbe0b9d97948b39e9ba2d3a1687edb8b56ee70ff0536dab4d0551f71ed0daee9e412449f5f099bcc15e4ef0554dc79f87fec5a0dea717c7054392bf444613937401bbef3c22fbf7e738c58779b981609a1f9c11dd6f0bbe9996e2773459e4cef247b02a9fc21296ac57a5b10561824310cfbdecc90e06598370e3698713fdbe2528ec4ef3dccaae701eedc3e54ad6e7af4e68e3b39bd2e97ac9119936c647a503511cb283df984cfd7c07f0f56aa8ae3166948ef3f41b0859934d0282010100815486aab0a0896bf97f13e3eb1f7f5c49195b49cc3b6277412a3688798b18f46422df479cb941b3b54e25964a3d69b897bcc8355160e58b4af29f1745dd2cabb670f634b9c058e6b3514947f2c27de5ed424f73b1e1f1be4a188911a0333f3a6688658b3ee8e3265a512e4deacadc470ee304ebb5224123afb461984fe8524fe0b6b30d32a59f6ed2dc74a96bc7cbfd1bb44e58a7092235c5d6272e12a2c862cb8c8cf5d109aa4fb1c6472875a14460c1ed5207c4b22bc494c7947eb7ca63a8cafd31361d000ddf16a2d79f13dd9140d979149b488cbf44945a5b6aaf13221bf4491ebbb7fca27ca20e221f49c3c37b89fcf2dc0e2cb63f8f8a9b7a142250590282010100b61d84ff934a4e437b16ee1b4b9fdf4ae13370b5385bde7a5464a123c0343df575f9e128ef9df944230d39cc9cf5dc0edb28b7e740b69ef024c1bfee39fcd5340ffaea0010160c535dc0920e7cd81be533d00fa554a1fc4d3e02c461569f5e7ca787f1515edf45b196b759884de652c38d5934cf92524e807b4d3b590bc39bc417ee4885a761d28ddadce6c8fdb3b961d3e7fd48064df9340a967f8b79997438841f48579a476ddb55088c308f68f2b29d01c6597a5a7c8d066284f63e37a68c3879c32aa3836675fd0eb2719883a91944561e9dd7e8aa6bb17157f08c48f8e6fae5c3e5a2bb6b5d580eec6c97ddcd9be0a49ef283a7031ad7aba8d438df4e950282010022fb8e5fcd9b767104e71244db53058c18061e1b0d1f63b73e2d59a95e2a10cd87426a33da13c287cdef8136e5e47e93fb9b30ad92628a7b543f48eb011a86356ab3cb480f27e391b018ca187d97af3d82e31861ecafa663db78aa89c3bd468e6aadefb3a43f78bc00b8014c95db54e9d21a017e8f21f671545edde9a965ea32dfff45cda37fca1aa5132f6c8eed222bd01fed5a6e7d639580c5955777a86544c2c4c939bdb8b4c486dda53072861a0334359bdb3758475e49d90d0539944e78cfcfd8fff55bb31a1cebc65b28f51e790701b2f7912188984f034e6e96e1c5251e33fe38fb221bce7a90a86857c5f56b6ca77307c45d5290b1f088ade082b349",
          "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\nCDvptGu4seq1lXstp0AnXpbIcZW5b+EUUhWdr8/ZFs7l10mne8OQWl69OHrkRej+\ncPFumghmOXec7/v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCd\nVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm+K6MJkPyrnaLIlXwgsl46VylUV\nVfEGCCMc+AA7v4B5af/x5RkUuajJuPRWRkW55dcF/60pZj9drj12ZStCLkPxPmwU\nkQkIBcLRJop0olEXdCfjOpqRF1w2cLkXRgCLzh/SMebk8q1wy0OspfB2AKbTHdAp\nFSQ9/dlDoCFl2jZ6a35Nrh3S6Lg2kDCAeV0lhQdswcFd2ejS5eBHUmVpsb/TldlX\n65/eMl00LRRCbnHv3BiHUV5TzepYNJIfkoYp50ju0JesQCTivyVdcEEfhzc5SM+O\niqfv+isKtH1RZgkeGu3sYFaLFVvZwnvFXz7ONfg9Y2281av0hToFHblNUEUCAwEA\nAQKCAgEA01Gb2G7fXb6cZKN4FxPdBJt0f1ZR/ZGMzoqbgLbWovtqqzNKtWmom1iY\nLgquNzCQKZ+iJ/llK4AtI+5cpoJMQz0B1AuwRzsWGQqL+xN8CnBLT0m0UBW/vuH2\ncERvB1lSWdcMfXmulfmyVDsBYuu3Y+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AX6PIfZxVF7d6all6jLf/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+K6MJkPyrnaLIlXwgsl46VylUV\nVfEGCCMc+AA7v4B5af/x5RkUuajJuPRWRkW55dcF/60pZj9drj12ZStCLkPxPmwU\nkQkIBcLRJop0olEXdCfjOpqRF1w2cLkXRgCLzh/SMebk8q1wy0OspfB2AKbTHdAp\nFSQ9/dlDoCFl2jZ6a35Nrh3S6Lg2kDCAeV0lhQdswcFd2ejS5eBHUmVpsb/TldlX\n65/eMl00LRRCbnHv3BiHUV5TzepYNJIfkoYp50ju0JesQCTivyVdcEEfhzc5SM+O\niqfv+isKtH1RZgkeGu3sYFaLFVvZwnvFXz7ONfg9Y2281av0hToFHblNUEUCAwEA\nAQKCAgEA01Gb2G7fXb6cZKN4FxPdBJt0f1ZR/ZGMzoqbgLbWovtqqzNKtWmom1iY\nLgquNzCQKZ+iJ/llK4AtI+5cpoJMQz0B1AuwRzsWGQqL+xN8CnBLT0m0UBW/vuH2\ncERvB1lSWdcMfXmulfmyVDsBYuu3Y+u4HEtu3/nRl97eHb5X5ARm0VbU39XXY0xF\nU0+yu70b8leBehc8B5X9vMUzl29KDQQWDyma9dwnKoFLNtW65RFrlUIXjx1VTKt6\nZFMDVIK5ga3UvY/9XVAIObI+MOvT84aPB1hMv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veRIYiYTwNObpbhxSUeM/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
    
    private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yZ9EWNSvwUj28H34cySpbZz3s4Xd\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 = 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 
    opened by adelapie 12
  • Remove custom PrivateKey exponents/coefficient

    Remove custom PrivateKey exponents/coefficient

    As discussed in #50, it removes option for custom exps/coef on PrivateKey constructor. This way, we can trust on these values for CRT-based primitives and any other future implementation.

    RFC state because I would like to discuss what's the best solution for PKCS#1 key file imports, and not-so-small repos depend on this (boto/boto, aws/aws-cli, google/oauth2client, ... ;) ).

    Alternatives I can think of:

    1. Overwrite file exps/coef (currently implemented): It just drops key file exps/coef, and recompute them for the new PrivateKey instance. Mathematically correct, but it could theoretically change behaviour for malformed key files (actually, we currently don't use these values, so I think it's safe).
    2. Overwrite file exps/coef, and warn user: Same as 1, and we also warn user about malformed key file (incorrect exps or coeff). Question is, how we warn them? (print(), log... ?)
    3. Use file exps/coef: Change calculated values to those provided by key file. It uses incorrect values if present, so I discard this option.
    opened by adamantike 12
  • Problems with tests on Fedora

    Problems with tests on Fedora

    Hi, I'm updating the Fedora package, but I'm not able to make the tests work. I'm not sure if it's a problem with how Fedora builds Python or there is something else going on. I would say that the majority of tests works properly, but the SHA3 ones fail with an error like the following (the type it expects does change on the various Python versions):

    ======================================================================
    FAIL: test_run_mypy (tests.test_mypy.MypyRunnerTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/builddir/build/BUILD/rsa-4.6/tests/test_mypy.py", line 27, in test_run_mypy
        self.fail('\n'.join(['Mypy errors:'] + messages))
    AssertionError: Mypy errors:
    rsa/pkcs1.py:65: error: Dict entry 0 has incompatible type "str": "Type[_Hash]"; expected "str": "Callable[[Union[bytes, memoryview]], _Hash]"
    rsa/pkcs1.py:66: error: Dict entry 1 has incompatible type "str": "Type[_Hash]"; expected "str": "Callable[[Union[bytes, memoryview]], _Hash]"
    rsa/pkcs1.py:67: error: Dict entry 2 has incompatible type "str": "Type[_Hash]"; expected "str": "Callable[[Union[bytes, memoryview]], _Hash]"
    Found 3 errors in 1 file (checked 30 source files)
    
    Mypy failed with status 1
    
    ----------------------------------------------------------------------
    Ran 94 tests in 7.514s
    
    FAILED (failures=1)
    Test failed: <unittest.runner.TextTestResult run=94 errors=0 failures=1>
    	Message:   b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
    	Encrypted: b'1\x8c\x82\xb7)\x81w\xe7$\x0bB\x92I\xae\xee\x9dT\xd1\xec\x1d\x0f\xb9/\xdb\xa3\xf1w+%o\xb41'
    	Decrypted: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
    	Message:   b'Euro=\xe2\x82\xac ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    	Encrypted: b'V^\x81\x02\xc5\xc72\x93\x9c\x13\xa1\xfc\xb7!\xf0\x93\x15oE\xdek\x11\xc8a\xaa\xa9C\xa5\xd2\x1a\xcc\x9b\xc8\x11\xd5\x80\xf2\xa8\xd75\x17\xa0\x959\x9f\xa7\xfc\xe9'
    	Decrypted: b'Euro=\xe2\x82\xac ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    error: Test failed: <unittest.runner.TextTestResult run=94 errors=0 failures=1>
    

    This happens with:

    Do you have any idea on the possible cause and work around?

    Thanks a lot!

    opened by Fale 11
  • python-rsa 4.1 dropped Python 2 support but did not add a `python_requires>=3` stanza in setup.py

    python-rsa 4.1 dropped Python 2 support but did not add a `python_requires>=3` stanza in setup.py

    This change breaks users of rsa package who are still on Python 2 and who do not set an upper bound on rsa to be rsa<4.1 (or lower). It also breaks Python 2 users of any other library that depends on rsa with an open upper bound.

    A clean way to fix current situation would be to release a new version: (for example 4.3), using the sources of 4.0 (which are still Py2 compatible), and then release the most recent released sources in a follow-up release (4.4), and add a stanza python_requires>=3 or perhaps python_requires>=3.5 (depending on which py3 versions you support).

    Note that yanking released versions may cause other breakages (see for example discussion in https://github.com/hamcrest/PyHamcrest/issues/131), so a fix forward would be a cleaner way to address this.

    critical 
    opened by tvalentyn 10
  • Allow 'raw' PKCS1 signatures

    Allow 'raw' PKCS1 signatures

    This provides more convenient compatability with other libraries that use such raw signatures in intermediate results. In particular, it matches the behavior of openssl rsautl -sign.

    unit tests needed 
    opened by joostrijneveld 10
  • Unit test for Mersenne primes

    Unit test for Mersenne primes

    Checks Mersenne primes' primality. Tests bigger numbers, so it also checks Miller-Rabin's correct result for bigger bitsizes (and less rounds after merging #58).

    ~~It could help with #54, by giving more testcases and reducing the random factor affecting test coverage.~~ 9a9e08c fixed this.

    opened by adamantike 10
  • No encoding specified in setup.py

    No encoding specified in setup.py

    Originally reported by: Seun D (Bitbucket: seundawodu, GitHub: seundawodu)


    Non-ASCII character in setup.py and no encoding set.

    #!python
    
    
    # -*- coding: utf-8 -*-#
    #  Copyright 2011 Sybren A. Stüvel <[email protected]>
    
    
    

    which causes setup.py install to fail (and installs of packages using rsa to fail) in some cases.

    The above snippet should fix it


    • Bitbucket: https://bitbucket.org/sybren/python-rsa/issue/29
    bug major 
    opened by sybrenstuvel 10
  • Fix python3 support

    Fix python3 support

    Originally reported by: Sybren Stüvel (Bitbucket: sybren, GitHub: sybren)


    Before releasing version 3.0, the module should work on python 3.


    • Bitbucket: https://bitbucket.org/sybren/python-rsa/issue/7
    enhancement major 
    opened by sybrenstuvel 9
  • Bump certifi from 2021.10.8 to 2022.12.7

    Bump certifi from 2021.10.8 to 2022.12.7

    Bumps certifi from 2021.10.8 to 2022.12.7.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • 4.9: pytest is failing in `tests/test_mypy.py::MypyRunnerTest::test_run_mypy` unit

    4.9: pytest is failing in `tests/test_mypy.py::MypyRunnerTest::test_run_mypy` unit

    I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

    • python3 -sBm build -w --no-isolation
    • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
    • install .whl file in </install/prefix>
    • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

    Here is pytest output:

    + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-rsa-4.9-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-rsa-4.9-2.fc35.x86_64/usr/lib/python3.8/site-packages
    + /usr/bin/pytest -ra -q
    =========================================================================== test session starts ============================================================================
    platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
    rootdir: /home/tkloczko/rpmbuild/BUILD/python-rsa-version-4.9, configfile: tox.ini
    plugins: cov-4.0.0
    collected 87 items
    
    tests/test_cli.py ..............                                                                                                                                     [ 16%]
    tests/test_common.py .........                                                                                                                                       [ 26%]
    tests/test_integers.py ..                                                                                                                                            [ 28%]
    tests/test_key.py ......                                                                                                                                             [ 35%]
    tests/test_load_save_keys.py ............                                                                                                                            [ 49%]
    tests/test_mypy.py F                                                                                                                                                 [ 50%]
    tests/test_parallel.py .                                                                                                                                             [ 51%]
    tests/test_pem.py .........                                                                                                                                          [ 62%]
    tests/test_pkcs1.py .................                                                                                                                                [ 81%]
    tests/test_pkcs1_v2.py ...                                                                                                                                           [ 85%]
    tests/test_prime.py ....                                                                                                                                             [ 89%]
    tests/test_strings.py .                                                                                                                                              [ 90%]
    tests/test_transform.py ........                                                                                                                                     [100%]
    
    ================================================================================= FAILURES =================================================================================
    _______________________________________________________________________ MypyRunnerTest.test_run_mypy _______________________________________________________________________
    
    self = <tests.test_mypy.MypyRunnerTest testMethod=test_run_mypy>
    
        def test_run_mypy(self):
            proj_root = pathlib.Path(__file__).parent.parent
            args = [
                "--incremental",
                "--ignore-missing-imports",
                f"--python-version={sys.version_info.major}.{sys.version_info.minor}",
            ] + [str(proj_root / dirname) for dirname in test_modules]
    
            result = mypy.api.run(args)
    
            stdout, stderr, status = result
    
            messages = []
            if stderr:
                messages.append(stderr)
            if stdout:
                messages.append(stdout)
            if status:
                messages.append("Mypy failed with status %d" % status)
            if messages and not all("Success" in message for message in messages):
    >           self.fail("\n".join(["Mypy errors:"] + messages))
    E           AssertionError: Mypy errors:
    E           rsa/key.py:68: error: Missing return statement  [empty-body]
    E           rsa/key.py:80: error: Missing return statement  [empty-body]
    E           rsa/key.py:91: error: Missing return statement  [empty-body]
    E           rsa/key.py:98: error: Missing return statement  [empty-body]
    E           Found 4 errors in 1 file (checked 28 source files)
    E
    E           Mypy failed with status 1
    
    tests/test_mypy.py:31: AssertionError
    
    ---------- coverage: platform linux, python 3.8.15-final-0 -----------
    Name               Stmts   Miss  Cover   Missing
    ------------------------------------------------
    rsa/__init__.py        7      0   100%
    rsa/asn1.py            8      0   100%
    rsa/cli.py           154      7    95%   73-76, 195-196, 278
    rsa/common.py         54      9    83%   166-178
    rsa/core.py           20      3    85%   26, 37, 40
    rsa/key.py           243     23    91%   135-137, 191, 245, 248, 261, 264, 269, 378, 421, 424, 443, 446, 460, 545, 733, 750, 818, 821, 825-828
    rsa/parallel.py       23      4    83%   34-39
    rsa/pem.py            50      3    94%   54, 77, 80
    rsa/pkcs1.py         117     14    88%   113, 162, 305, 408-417, 432, 440-443
    rsa/pkcs1_v2.py       12      0   100%
    rsa/prime.py          53      1    98%   83
    rsa/randnum.py        30      0   100%
    rsa/transform.py      11      0   100%
    rsa/util.py           27      4    85%   76-77, 96-97
    ------------------------------------------------
    TOTAL                809     68    92%
    
    ========================================================================= short test summary info ==========================================================================
    FAILED tests/test_mypy.py::MypyRunnerTest::test_run_mypy - AssertionError: Mypy errors:
    ====================================================================== 1 failed, 86 passed in 16.66s =======================================================================
    

    Here is list of installed modules in build env

    Package                       Version
    ----------------------------- -----------------
    alabaster                     0.7.12
    appdirs                       1.4.4
    attrs                         22.1.0
    Babel                         2.11.0
    Brlapi                        0.8.3
    build                         0.9.0
    charset-normalizer            3.0.1
    contourpy                     1.0.6
    coverage                      6.5.0
    cssselect                     1.1.0
    cycler                        0.11.0
    distro                        1.8.0
    dnspython                     2.2.1
    docutils                      0.19
    exceptiongroup                1.0.0
    extras                        1.0.0
    fixtures                      4.0.0
    fonttools                     4.38.0
    gpg                           1.17.1-unknown
    idna                          3.4
    imagesize                     1.4.1
    importlib-metadata            5.1.0
    iniconfig                     1.1.1
    Jinja2                        3.1.2
    kiwisolver                    1.4.4
    libcomps                      0.1.19
    louis                         3.23.0
    lxml                          4.9.1
    MarkupSafe                    2.1.1
    matplotlib                    3.6.2
    mypy                          0.990
    mypy-extensions               0.4.3
    numpy                         1.23.1
    olefile                       0.46
    packaging                     21.3
    pbr                           5.9.0
    pep517                        0.13.0
    Pillow                        9.3.0
    pip                           22.3.1
    pluggy                        1.0.0
    poetry-core                   1.4.0
    pyasn1                        0.4.8
    Pygments                      2.13.0
    PyGObject                     3.42.2
    pyparsing                     3.0.9
    pytest                        7.2.0
    pytest-cov                    4.0.0
    python-dateutil               2.8.2
    pytz                          2022.4
    requests                      2.28.1
    rpm                           4.17.0
    scour                         0.38.2
    setuptools                    65.6.3
    six                           1.16.0
    snowballstemmer               2.2.0
    Sphinx                        5.3.0
    sphinxcontrib-applehelp       1.0.2.dev20221204
    sphinxcontrib-devhelp         1.0.2.dev20221204
    sphinxcontrib-htmlhelp        2.0.0
    sphinxcontrib-jsmath          1.0.1.dev20221204
    sphinxcontrib-qthelp          1.0.3.dev20221204
    sphinxcontrib-serializinghtml 1.1.5
    testtools                     2.5.0
    tomli                         2.0.1
    typing_extensions             4.4.0
    urllib3                       1.26.12
    wheel                         0.38.4
    zipp                          3.11.0
    
    opened by kloczek 2
  • rsa/pkcs1.py: Clarify functionality of sign_hash()

    rsa/pkcs1.py: Clarify functionality of sign_hash()

    Clarify functionality that a hash is not computed, rather a precomputed (given) hash is being signed.

    Signed-off-by: Moritz Fischer [email protected]

    opened by mfischer 0
  • multiprime support

    multiprime support

    This PR adds multiprime support to help this library meet PKCS#1 v2.1. It's a big one! I didn't want to break existing user API to keep it backwards compatible. While this means it could be merged into the current library version, it also means the code gets more complicated at times (see __repr__ and __getstate__ for examples).

    I also realized that some users may be depending on return type guarantees. For example, if a user is using gen_keys directly (which I think is supposed to be an internal method, but it doesn't have a leading _) then their code would break because I made it behave differently for multiprime vs conventional key generation. To prevent this, I changed the return type to typing.Tuple, which will stop it from breaking but makes the typing less useful. I could've made it typing.Union[typing.Tuple[int, int, int, int],typing.Tuple[int, int, int, int, typing.List[int]] but I don't think anyone would've appreciated that! I also have the changes from #205 and #206 since I found them in this branch first.

    opened by myheroyuki 2
  • language correction and speed-up

    language correction and speed-up

    Addresses #205. I also moved an assert check up since the blinding will usually add length to the signed message which caused the appending zeroes test to fail with a different exception. If this doesn't seem right let me know!

    opened by myheroyuki 1
Owner
Sybren A. Stüvel
Sybren A. Stüvel
A hybrid(AES + RSA) encryptor in python.

python-file-encryptor A hybrid(AES + RSA) encryptor in python. Tasted on Windows and Linux(Kali). Install Requirements Use the package manager pip to

Alireza Kalhor 8 Jun 24, 2022
Um sistema de Criptografia RSA feito totalmente em Python

Um sistema de Criptografia RSA feito totalmente em Python

Luis Müdder 3 Nov 23, 2021
Deriving RSA public keys from message-signature pairs

The repository contains: Experimental code to calculate RSA public keys based on two known message-signature pairs

Silent Signal 120 Dec 31, 2022
Simple encryption/decryption utility using Pycryptodome module. Working with AES and RSA algorithms.

EncypherUtil Simple encryption/decryption utility using PyCryptodome module. Working with AES and RSA algorithms. THIS UTILITY IS NOT LICENSED AS CRYP

Egor Yakubovich 0 Jun 14, 2022
SSEPy: Implementation of searchable symmetric encryption in pure Python

SSEPy: Implementation of searchable symmetric encryption in pure Python Searchable symmetric encryption, one of the research hotspots in applied crypt

null 33 Dec 5, 2022
📊Python implementation of the Colin Talks Crypto Bitcoin Bull Run Index (CBBI).

Colin Talks Crypto Bitcoin Bull Run Index (CBBI) This is a Python implementation of the Colin Talks Crypto Bitcoin Bull Run Index (CBBI). It makes use

Kamil Monicz 86 Jan 2, 2023
Python implementation of a blockchain.

The goal of this project is to explain and to make clearer how is a blockchain structured at the very core. It's not built with the intention to replicate an advanced blockchain like Bitcoin or Ethereum

Rahul raikwar 5 Jan 28, 2022
Blockchain Python Implementation

Blockchain Python Implementation

0918nobita 2 Nov 21, 2021
A Python implementation of CWT/COSE.

Python CWT - A Python implementation of CWT/COSE Python CWT is a CBOR Web Token (CWT) and CBOR Object Signing and Encryption (COSE) implementation com

Ajitomi Daisuke 13 Dec 14, 2022
Simple crypto & blockchain implementation written in Python

JaamoCoin - simple Python blockchain example This is a very simple blockchain example written in Python. Based on this tutorial: https://medium.com/co

Jaakko Alajoki 1 Jan 7, 2022
A python implementation of our standard object-oriented encryption package, shipped with most apps.

Encryption Manager (python edition) VerseGroup's native encryption manager adapted for python applications. Function Generate new set of private and p

Verse Group LLC 2 Oct 30, 2022
Implementation of Smart Batch Auction for NFT launches on Tezos.

NFT Smart Batch Auction Smart Batch Auctions are an improvement over the traditional first come first serve (FCFS) NFT drops. FCFS design has been in

Anshu Jalan 5 May 6, 2022
The leading native Python SSHv2 protocol library.

Paramiko Paramiko: Python SSH module Copyright: Copyright (c) 2009 Robey Pointer <[email protected]> Copyright: Copyright (c) 2020 Jeff Forcier <

null 8.1k Jan 8, 2023
Python binding to the Networking and Cryptography (NaCl) library

PyNaCl: Python binding to the libsodium library PyNaCl is a Python binding to libsodium, which is a fork of the Networking and Cryptography library. T

Python Cryptographic Authority 941 Jan 4, 2023
cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.

pyca/cryptography cryptography is a package which provides cryptographic recipes and primitives to Python developers. Our goal is for it to be your "c

Python Cryptographic Authority 5.2k Dec 30, 2022
A self-contained cryptographic library for Python

PyCryptodome PyCryptodome is a self-contained Python package of low-level cryptographic primitives. It supports Python 2.7, Python 3.4 and newer, and

Helder Eijs 2.2k Jan 8, 2023
Python ASN.1 library with a focus on performance and a pythonic API

asn1crypto A fast, pure Python library for parsing and serializing ASN.1 structures. Features Why Another Python ASN.1 Library? Related Crypto Librari

Will Bond 282 Dec 11, 2022
Bitcoin Clipper malware made in Python.

a BTC Clipper or a "Bitcoin Clipper" is a type of malware designed to target cryptocurrency transactions.

Nightfall 96 Dec 30, 2022