Skip to content

shift/agemobile

 
 

Repository files navigation

agemobile

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

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 - Build artifact is located in build/android folder.)
  2. Add age.aar to libs folder in your app project
  3. Include dependency for Android in build.gradle
dependencies {
    ...
    // AgeMobile aar from Go
    implementation fileTree(include: ['age.aar'], dir: 'libs')
}

iOS

  1. Get Age.xcframework (You can get Age.xcframework from release page or clone the repo and execute make build-ios to build yourself - Build artifact is located in build/ios folder.)
  2. Copy Age.xcframework into iOS project framework folder
  3. Import Age in Swift

Usage

Android

There is an example project in _examples/android folder

Generate key

import agemobile.Agemobile;

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

Decrypt

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

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

There is an example project in _examples/ios folder

Generate Key

import Age

let identity = AgemobileGenerateX25519Identity(nil)
let privateKey = identity?.string()
let publicKey = identity?.recipient()?.string()

Encrypt

import Age

let input = "my secret"
let encrypted = AgemobileEncrypt(identity?.recipient()?.string(), input, true, nil)

Decrypt

import Age

let decrypted = AgemobileDecrypt(identity?.string(), encrypted, nil)

Contributing

PR's are welcome. Please read CONTRIBUTING.md for more info

License

MIT

About

Gomobile support for Age

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 64.7%
  • C 16.1%
  • Go 11.3%
  • Java 4.8%
  • Swift 2.7%
  • Makefile 0.4%