1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88pyrage
======
[](https://github.com/woodruffw/pyrage/actions/workflows/ci.yml)
[](https://badge.fury.io/py/pyrage)
[](https://pepy.tech/projects/pyrage)
Python bindings for the [Rust implementation of `age`](https://github.com/str4d/rage).
## Index
* [Installation](#installation)
* [Usage](#usage)
* [Development](#development)
* [Licensing](#licensing)
## Installation
You can install `pyrage` with `pip`:
```console
$ python -m pip install pyrage
```
[PEP 561](https://peps.python.org/pep-0561/)-style type stubs are also available:
```console
$ python -m pip install pyrage-stubs
```
See the [development instructions](#development) below for manual installations.
## Usage
### Identity generation (x25519 only)
```python
from pyrage import x25519
ident = x25519.Identity.generate()
# returns the public key
ident.to_public()
# returns the private key
str(ident)
```
### Identity-based encryption and decryption
```python
from pyrage import encrypt, decrypt, ssh, x25519
# load some identities
alice = x25519.Identity.from_str("AGE-SECRET-KEY-...")
bob = ssh.Identity.from_buffer(b"---BEGIN OPENSSH PRIVATE KEY----...")
# load some recipients
carol = x25519.Recipient.from_str("age1z...")
dave = ssh.Recipient.from_str("ssh-ed25519 ...")
# encryption
encrypted = encrypt(b"bob can't be trusted", [carol, dave, alice.to_public()])
# decryption
decrypted = decrypt(encrypted, [alice, bob])
```
### Passphrase encryption and decryption
```python
from pyrage import passphrase
encrypted = passphrase.encrypt(b"something secret", "my extremely secure password")
decrypted = passphrase.decrypt(encrypted, "my extremely secure password")
```
## Development
```console
$ source env/bin/activate
$ make develop
```
## Licensing
`pyrage` is released and distributed under the terms of the [MIT License](./LICENSE).