Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinX committed Jun 17, 2022
1 parent e739756 commit a2e6f7f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,99 @@
# agemobile
Gomobile support for Age

Gomobile bind is limited by types and while it allows you to generate identity, you cannot encrypt/decrypt.

-- working on it--
This package wraps age library into usable mobile library.

<img src="./misc/android_screenshot.png" width="250">

## Install

### Android

1. Get `age.aar` (You can get `age.aar` from [release page]() or clone the repo and execute `make build-android` to build .aar yourself)
2. Create `libs` folder in your app project android app and copy `age.aar`
3. Include dependency for Android in `build.gradle`

```gradle
dependencies {
...
// AgeMobile aar from Go
implementation fileTree(include: ['age.aar'], dir: 'libs')
}
```

### iOS

No documentation, PR's welcome

## Usage

### Android

There is an example project in [\_examples/android](./_examples/android/AgeMobile) folder

#### Generate key

```java
import agemobile.Agemobile;

try {
age.X25519Identity identity = Agemobile.generateX25519Identity();
String privateKey = identity.string();
String publicKey = identity.recipient().string();
} catch (Exception e) {
e.printStackTrace();
}
```

#### Decrypt

```java
import agemobile.Agemobile;

// decrypt text
try {
String decryptedText = Agemobile.decrypt("age-key/s","with or without armor encrypted text");
} catch (Exception e) {
e.printStackTrace();
}

// decrypt file
try {
Agemobile.decrypt("age-key/s","input file to decrypt", "output path where to write decrypted file");
} catch (Exception e) {
e.printStackTrace();
}
```

#### Encrypt

```java
import agemobile.Agemobile;

// encrypt text
try {
Agemobile.encrypt("age-keys","text to encrypt");
} catch (Exception e) {
e.printStackTrace();
}

// encrypt file
try {
Agemobile.encryptFile("age-keys","input file to encrypt", "output path where to write encrypted file");
} catch (Exception e) {
e.printStackTrace();
}
```

### iOS

No examples, yet! PR's welcome.

## Contributing

PR's are welcome. Please read [CONTRIBUTING.md](https://github.com/MarinX/electrumrpc/blob/master/CONTRIBUTING.md) for more info

## License

MIT
18 changes: 18 additions & 0 deletions agemobile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package agemobile

import (
"filippo.io/age"
_ "golang.org/x/mobile/bind"
)

// GenerateX25519Identity randomly generates a new X25519Identity.
func GenerateX25519Identity() (*age.X25519Identity, error) {
return age.GenerateX25519Identity()
}

// ParseX25519Identity returns a new X25519Identity from a Bech32 private key
// encoding with the "AGE-SECRET-KEY-1" prefix.
func ParseX25519Identity(s string) (*age.X25519Identity, error) {
return age.ParseX25519Identity(s)
}

// ParseX25519Recipient returns a new X25519Recipient from a Bech32 public key
// encoding with the "age1" prefix.
func ParseX25519Recipient(s string) (*age.X25519Recipient, error) {
return age.ParseX25519Recipient(s)
}

0 comments on commit a2e6f7f

Please sign in to comment.