-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |