Beispiel #1
0
    def test_rsa():
        rsapriv = botan2.private_key('rsa', 1536, botan2.rng())
        rsapub = rsapriv.get_public_key()

        print("rsapub %s SHA-1 fingerprint: %s estimated strength %d (len %d)" % (
            rsapub.algo_name(), rsapub.fingerprint("SHA-1"),
            rsapub.estimated_strength(), len(rsapub.encoding())
        ))

        dec = botan2.pk_op_decrypt(rsapriv, "EME1(SHA-256)")
        enc = botan2.pk_op_encrypt(rsapub, "EME1(SHA-256)")

        sys_rng = botan2.rng()
        symkey = sys_rng.get(32)
        ctext = enc.encrypt(symkey, sys_rng)
        print("ptext   \'%s\' (%d)" % (hex_encode(symkey), len(symkey)))
        print("ctext   \'%s\' (%d)" % (hex_encode(ctext), len(ctext)))
        print("decrypt \'%s\' (%d)\n" % (hex_encode(dec.decrypt(ctext)),
                                         len(dec.decrypt(ctext))))

        signer = botan2.pk_op_sign(rsapriv, 'EMSA4(SHA-384)')

        signer.update('messa')
        signer.update('ge')
        sig = signer.finish(botan2.rng())

        print("EMSA4(SHA-384) signature: %s" % hex_encode(sig))

        verify = botan2.pk_op_verify(rsapub, 'EMSA4(SHA-384)')

        verify.update('mess')
        verify.update('age')
        print("good sig accepted? %s" % verify.check_signature(sig))

        verify.update('mess of things')
        verify.update('age')
        print("bad sig accepted?  %s" % verify.check_signature(sig))

        verify.update('message')
        print("good sig accepted? %s\n" % verify.check_signature(sig))
Beispiel #2
0
    def test_rsa():
        rsapriv = botan2.private_key('rsa', 1536, botan2.rng())
        rsapub = rsapriv.get_public_key()

        print("rsapub %s SHA-1 fingerprint: %s estimated strength %d (len %d)" % (
            rsapub.algo_name(), rsapub.fingerprint("SHA-1"),
            rsapub.estimated_strength(), len(rsapub.encoding())
        ))

        dec = botan2.pk_op_decrypt(rsapriv, "EME1(SHA-256)")
        enc = botan2.pk_op_encrypt(rsapub, "EME1(SHA-256)")

        sys_rng = botan2.rng()
        symkey = sys_rng.get(32)
        ctext = enc.encrypt(symkey, sys_rng)
        print("ptext   \'%s\' (%d)" % (hex_encode(symkey), len(symkey)))
        print("ctext   \'%s\' (%d)" % (hex_encode(ctext), len(ctext)))
        print("decrypt \'%s\' (%d)\n" % (hex_encode(dec.decrypt(ctext)),
                                         len(dec.decrypt(ctext))))

        signer = botan2.pk_op_sign(rsapriv, 'EMSA4(SHA-384)')

        signer.update('messa')
        signer.update('ge')
        sig = signer.finish(botan2.rng())

        print("EMSA4(SHA-384) signature: %s" % hex_encode(sig))

        verify = botan2.pk_op_verify(rsapub, 'EMSA4(SHA-384)')

        verify.update('mess')
        verify.update('age')
        print("good sig accepted? %s" % verify.check_signature(sig))

        verify.update('mess of things')
        verify.update('age')
        print("bad sig accepted?  %s" % verify.check_signature(sig))

        verify.update('message')
        print("good sig accepted? %s\n" % verify.check_signature(sig))
Beispiel #3
0
    def test_rsa(self):
        rng = botan2.rng()
        rsapriv = botan2.private_key('RSA', '1024', rng)
        self.assertEqual(rsapriv.algo_name(), 'RSA')

        rsapub = rsapriv.get_public_key()
        self.assertEqual(rsapub.algo_name(), 'RSA')
        self.assertEqual(rsapub.estimated_strength(), 80)

        enc = botan2.pk_op_encrypt(rsapub, "OAEP(SHA-256)")
        dec = botan2.pk_op_decrypt(rsapriv, "OAEP(SHA-256)")

        symkey = rng.get(32)
        ctext = enc.encrypt(symkey, rng)

        ptext = dec.decrypt(ctext)

        self.assertEqual(ptext, symkey)

        signer = botan2.pk_op_sign(rsapriv, 'EMSA4(SHA-384)')

        signer.update('messa')
        signer.update('ge')
        sig = signer.finish(botan2.rng())

        verify = botan2.pk_op_verify(rsapub, 'EMSA4(SHA-384)')

        verify.update('mess')
        verify.update('age')
        self.assertTrue(verify.check_signature(sig))

        verify.update('mess of things')
        verify.update('age')
        self.assertFalse(verify.check_signature(sig))

        verify.update('message')
        self.assertTrue(verify.check_signature(sig))
Beispiel #4
0
    def test_rsa(self):
        rng = botan2.rng()
        rsapriv = botan2.private_key('RSA', '1024', rng)
        self.assertEqual(rsapriv.algo_name(), 'RSA')

        rsapub = rsapriv.get_public_key()
        self.assertEqual(rsapub.algo_name(), 'RSA')
        self.assertEqual(rsapub.estimated_strength(), 80)

        enc = botan2.pk_op_encrypt(rsapub, "OAEP(SHA-256)")
        dec = botan2.pk_op_decrypt(rsapriv, "OAEP(SHA-256)")

        symkey = rng.get(32)
        ctext = enc.encrypt(symkey, rng)

        ptext = dec.decrypt(ctext)

        self.assertEqual(ptext, symkey)

        signer = botan2.pk_op_sign(rsapriv, 'EMSA4(SHA-384)')

        signer.update('messa')
        signer.update('ge')
        sig = signer.finish(botan2.rng())

        verify = botan2.pk_op_verify(rsapub, 'EMSA4(SHA-384)')

        verify.update('mess')
        verify.update('age')
        self.assertTrue(verify.check_signature(sig))

        verify.update('mess of things')
        verify.update('age')
        self.assertFalse(verify.check_signature(sig))

        verify.update('message')
        self.assertTrue(verify.check_signature(sig))