Pyjo.GCP.RSA - Signatures of RS256 of a key of RSA¶
from Pyjo.GCP.RSA import RSA
key = RSA.from_pem(info['private_key'])
signature = key.sign(b'header.payload')
# Or import the module, as in Google Python Style Guide
import Pyjo.GCP.RSA
key = Pyjo.GCP.RSA.from_pem(pem, backend='python')
token = key.jwt({'iss': 'reader@myproject.iam.gserviceaccount.com', 'iat': 1762257600}, key_id='3c5a...')
print(key.verify(b'header.payload', signature))
Pyjo.GCP.RSA is a private key of RSA, as the key of a service account
of Google Cloud has it, which signs with SHA-256 and the padding of PKCS #1
v1.5, as RS256 of JSON Web Signature, of RFC 7518, has it, and makes the
JSON Web Tokens of Pyjo.GCP.Credentials.ServiceAccount.
The signature is the one of the package cryptography when it is
installed, as the extra cryptography of the distribution installs it:
pip install 'Pyjo-GCP[cryptography]'
or of Python itself otherwise, whose signature is the same, as the padding of PKCS #1 v1.5 is not random. That one is not constant-time: it is for a key and a signature that are made on the machine that has the key, not for a server that signs what anyone sends it.
See also¶
Pyjo.GCP.Credentials.ServiceAccount, RFC 8017, RFC 7518,
RFC 7519, https://cryptography.io/.
Classes¶
- class Pyjo.GCP.RSA.Pyjo_GCP_RSA(n: int, e: int, d: int, p: int, q: int, *, backend: Backend | None = None)[source]¶
Pyjo.GCP.RSAinherits all attributes and methods fromPyjo.Baseand implements the following new ones.- __init__(n: int, e: int, d: int, p: int, q: int, *, backend: Backend | None = None) None[source]¶
key = Pyjo.GCP.RSA.new(n, e, d, p, q) key = Pyjo.GCP.RSA.new(n, e, d, p, q, backend='python')
Construct a new
Pyjo.GCP.RSAobject of the modulus, the public and the private exponent and the primes of a key, with the backend ofcryptographywhen it is installed, or of Python.
- __weakref__¶
list of weak references to the object
- backend: Backend¶
name = key.backend
The backend of the signatures,
cryptographyorpython.
- d¶
d = key.d
The private exponent of the key.
- e¶
e = key.e
The public exponent of the key, as
65537.
- classmethod from_pem(pem: str | bytes, *, backend: Backend | None = None) Pyjo_GCP_RSA[source]¶
key = Pyjo.GCP.RSA.from_pem(pem)
A new
Pyjo.GCP.RSAobject of a private key of RSA in PEM, of PKCS #8,BEGIN PRIVATE KEY, as the key of a service account has it, or of PKCS #1,BEGIN RSA PRIVATE KEY, without a password.
- jwt(claims: Mapping[str, Any], *, key_id: str | None = None) str[source]¶
token = key.jwt({'iss': email, 'aud': 'https://oauth2.googleapis.com/token', 'iat': iat, 'exp': exp}) token = key.jwt(claims, key_id=info['private_key_id'])
A JSON Web Token of RS256 of the claims, with the ID of the key in
kidof its header, as google-auth makes it.
- n¶
n = key.n
The modulus of the key.
- p¶
p = key.p
The first prime of the key.
- q¶
q = key.q
The second prime of the key.
- Pyjo.GCP.RSA.from_pem(pem: str | bytes, *, backend: Backend | None = None) Pyjo_GCP_RSA[source]¶
key = Pyjo.GCP.RSA.from_pem(pem)
Alias for
Pyjo_GCP_RSA.from_pem().