def test_sign_and_verify(self): for _ in range(1000): message = randbits(settings.RSA_BIT_LENGTH) pub, priv = find_pair_of_keys() signature = sign(message, priv) self.assertTrue(verify(message, signature, pub)) self.assertFalse(verify(message + 1, signature, pub))
def generate_rsa_keys_for_existing_users(apps, schema_editor): User = apps.get_model("fleet_management", "User") for user in User.objects.filter(rsa_priv_d=""): pub, priv = find_pair_of_keys() user.rsa_modulus_n = str(pub.n).zfill(6) user.rsa_pub_e = str(pub.e).zfill(6) user.rsa_priv_d = str(priv.d).zfill(6) user.save()
def regenerate_keys(self): pub, priv = find_pair_of_keys() self.rsa_modulus_n = str(pub.n).zfill(6) self.rsa_pub_e = str(pub.e).zfill(6) self.rsa_priv_d = str(priv.d).zfill(6)