Esempio n. 1
0
    def test_1024_3_unicode(self):
        n = "ABC30681295774F7CECA691EC17F4E762DA6DE70F198EAEE3CCE3A435FC006B971DC24E55904F1D2705758C041C2B0B18E8BFAE2C9CD96B50082D7D8C7342CBAB7F6E0622DA53B8B56DBDB24174F00173263CFECAE604795CDA2A037BC3A69B7C0090AA2DE1568998BCD6D70CC2E0574755B9F7986AE01CE8714A26144279CDB"
        e = "3"
        d = "728204561b8fa34fdf319b69d654def973c4944b4bbb47497dded1823fd559d0f692c34390adf68c4ae4e5d5812c75cbb45d51ec86890f2355ac8fe5da22c87b62449e2aa754422bc43d3ca32efa866227ad58178e7803897d074f1312740aa761cfc7ed753bb829d7a2ab091289d1676809bfd61276b43bb3a395714f167beb"
        p = "e200731c6e934a0fdc1d5ce5f66d08ba9478280f46e9cbed777029dd4811a7cd4aa66ad8365c5aa67b06b97e54ee8fec03adb2134f7359a427c7ffc468ef0231"
        q = "c28f8005c4138e39d462a3495a6a2dc96267a3ba11c2765a1aa77fbdd87ab1ef62aaf3e677df79b44d52b364db70bb6d559f4da51b8899d0d1d74272e496e0cb"
        dmp1 = "96aaf76849b786b53d68e8994ef35b270da5700a2f4687f3a4f5713e300bc53387199c90243d91c452047ba98df45ff2ad1e76b78a4ce66d6fdaaa82f09f56cb"
        dmq1 = "81b50003d80d097be2ec6cdb919c1e86419a6d26b681a43c11c4ffd3e5a7214a41c74d444fea5122de3722433cf5d248e3bf8918bd05bbe08be4d6f7430f4087"
        coeff = "a318fb95d3b10d6cfb0096fc3a3173377cf0952bf5d50fd3ccf678dd636ca1a1aeed8da416c8fba4395b00dc3e22823d1b2add8a4e1222d562af11bd6c78ad94"
        ctext = "077b843e2a9ee8550683c28def9dd2109a77275fa2006b6dbd2f73b5cb22e36d6f0ea7da3a1f71f7a072d568af7e817046166e17f165100da2ea80966967dbf30b2bde037fe8d586782e077d5014938e5c67ff06181b278850e7f3c783e8e1f54fd9f229c36ed889ce43b23fac723411d0be4f679b001f829ce267ead0c7aa76"
        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "안녕 세계여!")
Esempio n. 2
0
    def test_1024_10001_unicode(self):
        n = "a5261939975948bb7a58dffe5ff54e65f0498f9175f5a09288810b8975871e99af3b5dd94057b0fc07535f5f97444504fa35169d461d0d30cf0192e307727c065168c788771c561a9400fb49175e9e6aa4e23fe11af69e9412dd23b0cb6684c4c2429bce139e848ab26d0829073351f4acd36074eafd036a5eb83359d2a698d3"
        e = "10001"
        d = "8e9912f6d3645894e8d38cb58c0db81ff516cf4c7e5a14c7f1eddb1459d2cded4d8d293fc97aee6aefb861859c8b6a3d1dfe710463e1f9ddc72048c09751971c4a580aa51eb523357a3cc48d31cfad1d4a165066ed92d4748fb6571211da5cb14bc11b6e2df7c1a559e6d5ac1cd5c94703a22891464fba23d0d965086277a161"
        p = "d090ce58a92c75233a6486cb0a9209bf3583b64f540c76f5294bb97d285eed33aec220bde14b2417951178ac152ceab6da7090905b478195498b352048f15e7d"
        q = "cab575dc652bb66df15a0359609d51d1db184750c00c6698b90ef3465c99655103edbf0d54c56aec0ce3c4d22592338092a126a0cc49f65a4a30d222b411e58f"
        dmp1 = "1a24bca8e273df2f0e47c199bbf678604e7df7215480c77c8db39f49b000ce2cf7500038acfff5433b7d582a01f1826e6f4d42e1c57f5e1fef7b12aabc59fd25"
        dmq1 = "3d06982efbbe47339e1f6d36b1216b8a741d410b0c662f54f7118b27b9a4ec9d914337eb39841d8666f3034408cf94f5b62f11c402fc994fe15a05493150d9fd"
        coeff = "3a3e731acd8960b7ff9eb81a7ff93bd1cfa74cbd56987db58b4594fb09c09084db1734c8143f98b602b981aaa9243ca28deb69b5b280ee8dcee0fd2625e53250"
        ctext = "821c1ad4cc290dc4a0876dfc40365706a2be8dbd0d8e1df037649beed12a5757ac218c38b9e61286f4be9fba84f8e422605fcee477f52bb1fc956bb921772da4f2559de4eb328bb778405a169e7cc35e0081806615953d71d3a75a33ac9e828169f5163dd0ca4f04e49b66c47a56a5250469e4653fb36a1b4dd0794facbfb8d0"
        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "안녕 세계여!")
Esempio n. 3
0
    def test_1024_3(self):
        n = "ABC30681295774F7CECA691EC17F4E762DA6DE70F198EAEE3CCE3A435FC006B971DC24E55904F1D2705758C041C2B0B18E8BFAE2C9CD96B50082D7D8C7342CBAB7F6E0622DA53B8B56DBDB24174F00173263CFECAE604795CDA2A037BC3A69B7C0090AA2DE1568998BCD6D70CC2E0574755B9F7986AE01CE8714A26144279CDB"
        e = "3"
        d = "728204561b8fa34fdf319b69d654def973c4944b4bbb47497dded1823fd559d0f692c34390adf68c4ae4e5d5812c75cbb45d51ec86890f2355ac8fe5da22c87b62449e2aa754422bc43d3ca32efa866227ad58178e7803897d074f1312740aa761cfc7ed753bb829d7a2ab091289d1676809bfd61276b43bb3a395714f167beb"
        p = "e200731c6e934a0fdc1d5ce5f66d08ba9478280f46e9cbed777029dd4811a7cd4aa66ad8365c5aa67b06b97e54ee8fec03adb2134f7359a427c7ffc468ef0231"
        q = "c28f8005c4138e39d462a3495a6a2dc96267a3ba11c2765a1aa77fbdd87ab1ef62aaf3e677df79b44d52b364db70bb6d559f4da51b8899d0d1d74272e496e0cb"
        dmp1 = "96aaf76849b786b53d68e8994ef35b270da5700a2f4687f3a4f5713e300bc53387199c90243d91c452047ba98df45ff2ad1e76b78a4ce66d6fdaaa82f09f56cb"
        dmq1 = "81b50003d80d097be2ec6cdb919c1e86419a6d26b681a43c11c4ffd3e5a7214a41c74d444fea5122de3722433cf5d248e3bf8918bd05bbe08be4d6f7430f4087"
        coeff = "a318fb95d3b10d6cfb0096fc3a3173377cf0952bf5d50fd3ccf678dd636ca1a1aeed8da416c8fba4395b00dc3e22823d1b2add8a4e1222d562af11bd6c78ad94"
        ctext = "5e1802ddb76a399ff98e5ea9853ad704d70c0aa8cce73386c64e2fbf9a27614f2cb318c8e19cbf36a5b40f717f01c3ee1a681f7d314f1f9e5d2bbd9a81659f771911a9c9ba3a60b026c71246be0f04e8c9952495a439f2e316b631d91ef0e71b185017ff48bc54d333b5c43fe0d8742ff934d24094a5cb320ddcd668417a3d36"
        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "Hello World!")
Esempio n. 4
0
    def test_1024_10001(self):
        n = "a5261939975948bb7a58dffe5ff54e65f0498f9175f5a09288810b8975871e99af3b5dd94057b0fc07535f5f97444504fa35169d461d0d30cf0192e307727c065168c788771c561a9400fb49175e9e6aa4e23fe11af69e9412dd23b0cb6684c4c2429bce139e848ab26d0829073351f4acd36074eafd036a5eb83359d2a698d3"
        e = "10001"
        d = "8e9912f6d3645894e8d38cb58c0db81ff516cf4c7e5a14c7f1eddb1459d2cded4d8d293fc97aee6aefb861859c8b6a3d1dfe710463e1f9ddc72048c09751971c4a580aa51eb523357a3cc48d31cfad1d4a165066ed92d4748fb6571211da5cb14bc11b6e2df7c1a559e6d5ac1cd5c94703a22891464fba23d0d965086277a161"
        p = "d090ce58a92c75233a6486cb0a9209bf3583b64f540c76f5294bb97d285eed33aec220bde14b2417951178ac152ceab6da7090905b478195498b352048f15e7d"
        q = "cab575dc652bb66df15a0359609d51d1db184750c00c6698b90ef3465c99655103edbf0d54c56aec0ce3c4d22592338092a126a0cc49f65a4a30d222b411e58f"
        dmp1 = "1a24bca8e273df2f0e47c199bbf678604e7df7215480c77c8db39f49b000ce2cf7500038acfff5433b7d582a01f1826e6f4d42e1c57f5e1fef7b12aabc59fd25"
        dmq1 = "3d06982efbbe47339e1f6d36b1216b8a741d410b0c662f54f7118b27b9a4ec9d914337eb39841d8666f3034408cf94f5b62f11c402fc994fe15a05493150d9fd"
        coeff = "3a3e731acd8960b7ff9eb81a7ff93bd1cfa74cbd56987db58b4594fb09c09084db1734c8143f98b602b981aaa9243ca28deb69b5b280ee8dcee0fd2625e53250"
        ctext = "a05410a1fa7fbadc9d6e7a3f37cdd13d3894cfa26becad8f3c314c3221bf730a4e6fae9f53b88faddecb9f842b959705475192c1aca105bb3b910494bce1be58748f51f76d30c18f14beeda3ff797a7e838f019d8381955a8d804176820fefd9f53351b74af263747762cf0f1abec9bf3cd5d4c0595afb626098693de7906f11"
        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "Hello World!")
Esempio n. 5
0
    def test_512_10001(self):
        n = "C4E3F7212602E1E396C0B6623CF11D26204ACE3E7D26685E037AD2507DCE82FC28F2D5F8A67FC3AFAB89A6D818D1F4C28CFA548418BD9F8E7426789A67E73E41"
        e = "10001"
        d = "7cd1745aec69096129b1f42da52ac9eae0afebbe0bc2ec89253598dcf454960e3e5e4ec9f8c87202b986601dd167253ee3fb3fa047e14f1dfd5ccd37e931b29d"
        p = "f0e4dd1eac5622bd3932860fc749bbc48662edabdf3d2826059acc0251ac0d3b"
        q = "d13cb38fbcd06ee9bca330b4000b3dae5dae12b27e5173e4d888c325cda61ab3"
        dmp1 = "b3d5571197fc31b0eb6b4153b425e24c033b054d22b9c8282254fe69d8c8c593"
        dmq1 = "968ffe89e50d7b72585a79b65cfdb9c1da0963cceb56c3759e57334de5a0ac3f"
        coeff = "d9bc4f420e93adad9f007d0e5744c2fe051c9ed9d3c9b65f439a18e13d6e3908"
        ctext = "310957f91db99d063b6ddfbac5531102d9be3cf844a12fa8a6dcbe0c80f47912560b46f09996feb4926e2161f68bce8cacb28dc04b71257d3f62c1ec0baac10e"

        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "Hello World!")
Esempio n. 6
0
    def test_512_3_unicode(self):
        n = "BC86E3DC782C446EE756B874ACECF2A115E613021EAF1ED5EF295BEC2BED899D26FE2EC896BF9DE84FE381AF67A7B7CBB48D85235E72AB595ABF8FE840D5F8DB"
        e = "3"
        d = "7daf4292fac82d9f44e47af87348a1c0b9440cac1474bf394a1b929d729e5bbcf402f29a9300e11b478c091f7e5dacd3f8edae2effe3164d7e0eeada87ee817b"
        p = "ef3fc61e21867a900e01ee4b1ba69f5403274ed27656da03ed88d7902cce693f"
        q = "c9b9fcc298b7d1af568f85b50e749539bc01b10a68472fe1302058104821cd65"
        dmp1 = "9f7fd9696baefc6009569edcbd19bf8d576f89e1a439e6ad4905e50ac8899b7f"
        dmq1 = "867bfdd7107a8bca39b503ce09a30e267d567606f02f7540cac03ab5856bde43"
        coeff = "412d6b551d93ee1bd7dccafc63d7a6d031fc66035ecc630ddf75f949a378cd9d"
        ctext = "2ef455145d108cb2d6005e50aeae9646e5455cce473c3616089776dc70209e7cd5f2bd1cc64f38bee60c5c6840401d086319b2a294b11da3b369ac63d7e5dea5"

        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "안녕 세계여!")
Esempio n. 7
0
    def test_512_10001_unicode(self):
        n = "C4E3F7212602E1E396C0B6623CF11D26204ACE3E7D26685E037AD2507DCE82FC28F2D5F8A67FC3AFAB89A6D818D1F4C28CFA548418BD9F8E7426789A67E73E41"
        e = "10001"
        d = "7cd1745aec69096129b1f42da52ac9eae0afebbe0bc2ec89253598dcf454960e3e5e4ec9f8c87202b986601dd167253ee3fb3fa047e14f1dfd5ccd37e931b29d"
        p = "f0e4dd1eac5622bd3932860fc749bbc48662edabdf3d2826059acc0251ac0d3b"
        q = "d13cb38fbcd06ee9bca330b4000b3dae5dae12b27e5173e4d888c325cda61ab3"
        dmp1 = "b3d5571197fc31b0eb6b4153b425e24c033b054d22b9c8282254fe69d8c8c593"
        dmq1 = "968ffe89e50d7b72585a79b65cfdb9c1da0963cceb56c3759e57334de5a0ac3f"
        coeff = "d9bc4f420e93adad9f007d0e5744c2fe051c9ed9d3c9b65f439a18e13d6e3908"
        ctext = "9920217dbd3a69c4aac105ea22612bdd41cdcc70948bd914330e16cca21a90b4794b01628a319d6cbe44241fbd8eae03154fcbb33eab47518fcd294a798fb1ef"

        rsa = RSAKey()
        rsa.setPrivateEx(n, e, d, p, q, dmp1, dmq1, coeff)

        self.assertEqual(rsa.decrypt(ctext), "안녕 세계여!")
Esempio n. 8
0
    def encryptPassword(self):
        """
        Encrypt password By RSA.
        """
        # base64 to hex
        self.exponent = codecs.encode(base64.b64decode(
            self.publicKey["exponent"]),
                                      encoding="hex").decode("utf-8")
        self.modulus = codecs.encode(base64.b64decode(
            self.publicKey["modulus"]),
                                     encoding="hex").decode("utf-8")

        rsa = RSAKey()
        rsa.setPublic(self.modulus, self.exponent)
        cry_data = rsa.encrypt(self.password)

        # hex to base64
        return base64.b64encode(codecs.decode(cry_data,
                                              encoding="hex")).decode("utf-8")
Esempio n. 9
0
    del soup
    soup = BeautifulSoup(res.text, 'html.parser')

    # find sesskey parameter
    import re
    match = re.findall(r'"sesskey":"(.*?)"', str(soup.find('script', type='text/javascript')))

    # Generate E2 value
    jsonObj = {
        'userid': cf.NYSCEC_LOGIN_PARAM['username'], 
        'userpw': cf.NYSCEC_LOGIN_PARAM['password'], 
        'ssoChallenge': request_payload['ssoChallenge']
        }

    from jsbn import RSAKey
    rsa = RSAKey()
    rsa.setPublic(
        request_payload['keyModulus'],
        request_payload['keyExponent']
        )

    E2 = rsa.encrypt(json.dumps(jsonObj))
    
    request_payload = {
        "app_id": "yscec",
        "retUrl": cf.NYSCEC_BASE,
        "failUrl": cf.NYSCEC_LOGIN_INDEX,
        "baseUrl": cf.NYSCEC_BASE,
        "loginUrl": cf.NYSCEC_LOGIN_INDEX,
        "loginType": "invokeID",
        "ssoGubun": "Login",
Esempio n. 10
0
        payload['username'] = cf.NLUS_LOGIN_PARAM['username']
        payload['password'] = cf.NLUS_LOGIN_PARAM['password']

    print('posting to %s with\n%s' %
          (cf.NLUS_LOGIN_COURSEMOSLOGIN, json.dumps(payload, indent=3)))
    res = s.post(cf.NLUS_LOGIN_COURSEMOSLOGIN, payload)
    print('done. status code: %s' % (res.status_code))

    #
    # Step 5. Need to generate RSA Public Key
    # pip install pyjsbn-rsa
    # pip install six

    from jsbn import RSAKey

    rsa = RSAKey()
    rsa.setPublic(payload['keyModulus'], payload['keyExponent'])

    E2 = rsa.encrypt(
        json.dumps({
            'userid': payload['username'],
            'userpw': payload['password'],
            'ssoChallenge': payload['ssoChallenge']
        }))

    print('E2 encryption done: %s' % E2)

    #
    # Step 6. Toss again with E2 combined.
    with open('%s/PmSSOAuthService.json' % cf.NLUS_TEMPLATE_DIR,
              'r') as template:
Esempio n. 11
0
 def test_unicode(self):
     rsa = RSAKey()
     rsa.generate(1024, "10001")
     msg = '안녕 세계여!'
     cmsg = rsa.encrypt(msg)
     self.assertEqual(rsa.decrypt(cmsg), msg)
Esempio n. 12
0
 def test_basic(self):
     rsa = RSAKey()
     rsa.generate(1024, "10001")
     msg = 'Hello World!'
     cmsg = rsa.encrypt(msg)
     self.assertEqual(rsa.decrypt(cmsg), msg)