2019-05-13 13:45:24 +02:00
|
|
|
# GopenPGP Wrapper Library
|
2019-03-07 13:48:45 +01:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
## Download/Install
|
2019-03-07 13:48:45 +01:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
Manually `git clone` the repository into `$GOPATH/src/github.com/ProtonMail/go-pm-crypto`.
|
2019-03-07 13:48:45 +01:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
This library is meant to be used together with https://github.com/ProtonMail/crypto.
|
2019-03-07 13:48:45 +01:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
## Using with Go Mobile
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
Setup Go Mobile and build/bind the source code:
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
Go Mobile repo: https://github.com/golang/mobile
|
|
|
|
|
Go Mobile wiki: https://github.com/golang/go/wiki/Mobile
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
1. Install Go: `brew install go`
|
|
|
|
|
2. Install Gomobile: `go get -u golang.org/x/mobile/cmd/gomobile`
|
|
|
|
|
3. Install Gobind: `go install golang.org/x/mobile/cmd/gobind`
|
|
|
|
|
4. Install Android SDK and NDK using Android Studio
|
|
|
|
|
5. Set env: `export ANDROID_HOME="/AndroidSDK"` (path to your SDK)
|
|
|
|
|
6. Init gomobile: `gomobile init -ndk /AndroidSDK/ndk-bundle/` (path to your NDK)
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
7. Build examples:
|
|
|
|
|
`gomobile build -target=android #or ios`
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
Bind examples:
|
|
|
|
|
`gomobile bind -target ios -o frameworks/name.framework`
|
|
|
|
|
`gomobile bind -target android`
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
The bind will create framework for iOS and jar&aar files for Android (x86_64 and ARM).
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
## Other notes
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
This project uses glide to setup vendors.
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
Interfacing between Go and Swift:
|
|
|
|
|
https://medium.com/@matryer/tutorial-calling-go-code-from-swift-on-ios-and-vice-versa-with-gomobile-7925620c17a4.
|
2018-06-04 16:05:14 -07:00
|
|
|
|
2019-05-13 13:45:24 +02:00
|
|
|
If you use build.sh, you may need to modify the paths in it.
|
2019-05-14 08:07:56 +00:00
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
|
|
### Set up
|
|
|
|
|
|
|
|
|
|
### Encrypt and decrypt
|
|
|
|
|
|
|
|
|
|
### Generate key
|
2019-05-14 10:54:27 +02:00
|
|
|
Keys are generated with the `GenerateKey` function, that returns the armored key as a string and a potential error.
|
|
|
|
|
The library supports RSA with different key lengths or Curve25519 keys.
|
|
|
|
|
```
|
|
|
|
|
var pmCrypto = PmCrypto{}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
localPart = "name.surname"
|
|
|
|
|
domain = "example.com"
|
|
|
|
|
passphrase = "LongSecret"
|
|
|
|
|
rsaBits = 2048
|
|
|
|
|
ecBits = 256
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RSA
|
|
|
|
|
rsaKey, err := pmCrypto.GenerateKey(localPart, domain, passphrase, "rsa", rsaBits)
|
|
|
|
|
|
|
|
|
|
// Curve 25519
|
|
|
|
|
ecKey, err := pmCrypto.GenerateKey(localPart, domain, passphrase, "x25519", ecBits)
|
|
|
|
|
```
|
2019-05-14 08:07:56 +00:00
|
|
|
|
|
|
|
|
### Sign
|
|
|
|
|
|
|
|
|
|
### Detached signatures
|