Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brickchain/go-crypto.v2
https://github.com/brickchain/go-crypto.v2
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/brickchain/go-crypto.v2
- Owner: Brickchain
- Created: 2018-05-24T09:36:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-10T20:39:59.000Z (about 6 years ago)
- Last Synced: 2024-06-20T02:08:25.396Z (7 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# crypto-lib
## Usage
```
import (
"fmt"
"gopkg.in/square/go-jose.v1"
crypto "github.com/Brickchain/go-crypto.v1"
)func encrypt() {
// generate a new private key
key, err := crypto.NewKey()
if err != nil {
panic(err)
}
// get the recipients public key from somewhere...
pk, err := crypto.UnmarshalKey(SomeJsonBytes())
if err != nil {
panic(err)
}
// create a new "encrypter", it's like a manager for the encryption opteration
enc, err := crypto.NewEncrypter()
if err != nil {
panic(err)
}
// add the recipient
enc.AddRecipient(pk)
// encrypt some text
msg, err := enc.Encrypt([]byte("some text"))
if err != nil {
panic(err)
}
// print the JsonWebEncryption object serialized to JSON
fmt.Println(msg.FullSerialize())
}func decrypt(mykey *jose.JsonWebKey, message *jose.JsonWebEncryption) {
_, _, m, err := message.DecryptMulti(mykey)
if err != nil {
panic(err)
}
fmt.Println(string(m))
}func sign(mykey *jose.JsonWebKey) {
signer, err := crypto.NewSigner(mykey)
if err != nil {
panic(err)
}
signature, err := signer.Sign([]byte("some test string"))
if err != nil {
panic(err)
}fmt.Println(signature.FullSerialize())
}func verifySign(publicKey *jose.JsonWebKey, message *jose.JsonWebSignature) {
_, _, payload, err := message.VerifyMulti(publicKey)
if err != nil {
panic(err)
}
fmt.Println(string(payload))
}
```