diff --git a/README.md b/README.md index a2640e5..d014409 100644 --- a/README.md +++ b/README.md @@ -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-- \ No newline at end of file +This package wraps age library into usable mobile library. + + + +## 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 diff --git a/agemobile.go b/agemobile.go index 4dc4eb8..01dcc9b 100644 --- a/agemobile.go +++ b/agemobile.go @@ -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) +}