Skip to content

Commit 765a9bb

Browse files
authored
Update README.md
Define `sign_ps256` function.
1 parent 30bf84a commit 765a9bb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ try:
126126
]
127127
}
128128

129+
# Example of using Python crypto to sign data using openssl with Ps256
130+
from cryptography.hazmat.primitives import hashes, serialization
131+
from cryptography.hazmat.primitives.asymmetric import padding
132+
133+
def sign_ps256(data: bytes, key_path: str) -> bytes:
134+
with open(key_path, "rb") as key_file:
135+
private_key = serialization.load_pem_private_key(
136+
key_file.read(),
137+
password=None,
138+
)
139+
signature = private_key.sign(
140+
data,
141+
padding.PSS(
142+
mgf=padding.MGF1(hashes.SHA256()),
143+
salt_length=padding.PSS.MAX_LENGTH
144+
),
145+
hashes.SHA256()
146+
)
147+
return signature
148+
129149
# Create a builder add a thumbnail resource and an ingredient file.
130150
builder = Builder(manifest_json)
131151

0 commit comments

Comments
 (0)