def test_to_dict(self, private_key): key = RSAKey(private_key, ALGORITHMS.RS256) self.assert_parameters(key.to_dict(), private=True) self.assert_parameters(key.public_key().to_dict(), private=False) self.assert_roundtrip(key) self.assert_roundtrip(key.public_key())
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) pem = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption()) pem = str(pem, 'utf-8') public_key = private_key.public_key() rsakey = RSAKey(public_key, ALGORITHMS.RS256) print(rsakey.to_dict()) tomorrow = datetime.now() + timedelta(days=1) tomorrow_in_seconds = tomorrow.timestamp() payload = { "sub": "a3bc91e1-dd79-433c-a3be-d5fe5ad5c608", "email_verified": False, "iss": "https://cognito-idp.us-east-2.amazonaws.com/us-east-2_rBDyyW1zu", "cognito:username": "******", "custom:Role": "Administrator", "aud": "f2alqmli8o74m8f63eb9qkdmm", "event_id": "51a8f501-b992-46ec-afd2-9eabf9ee36ff", "token_use": "id", "auth_time": 1564173531, "custom:Client": "High Peaks Solutions",