Skip to content

Commit 64a4f2f

Browse files
authored
doc: add crypto API example in python-sdk-docs (#729)
Signed-off-by: KentHsu <[email protected]>
1 parent 10ca7b7 commit 64a4f2f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

daprdocs/content/en/python-sdk-docs/python-client.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,40 @@ def main():
356356
- Learn more about using a distributed lock: [How-To: Use a lock]({{< ref howto-use-distributed-lock.md >}}).
357357
- Visit [Python SDK examples](https://github.com/dapr/python-sdk/blob/master/examples/distributed_lock) for code samples and instructions to try out distributed lock.
358358

359+
### Cryptography
360+
361+
```python
362+
from dapr.clients import DaprClient
363+
364+
message = 'The secret is "passw0rd"'
365+
366+
def main():
367+
with DaprClient() as d:
368+
resp = d.encrypt(
369+
data=message.encode(),
370+
options=EncryptOptions(
371+
component_name='crypto-localstorage',
372+
key_name='rsa-private-key.pem',
373+
key_wrap_algorithm='RSA',
374+
),
375+
)
376+
encrypt_bytes = resp.read()
377+
378+
resp = d.decrypt(
379+
data=encrypt_bytes,
380+
options=DecryptOptions(
381+
component_name='crypto-localstorage',
382+
key_name='rsa-private-key.pem',
383+
),
384+
)
385+
decrypt_bytes = resp.read()
386+
387+
print(decrypt_bytes.decode()) # The secret is "passw0rd"
388+
```
389+
390+
- For a full list of state operations visit [How-To: Use the cryptography APIs]({{< ref howto-cryptography.md >}}).
391+
- Visit [Python SDK examples](https://github.com/dapr/python-sdk/tree/master/examples/crypto) for code samples and instructions to try out cryptography
392+
359393
### Workflow
360394

361395
```python

0 commit comments

Comments
 (0)