Skip to content

Instantly share code, notes, and snippets.

@kaloyan-raev
Last active July 18, 2019 16:03
Show Gist options
  • Save kaloyan-raev/7b216c2a180dde36bac9bc7614bb138c to your computer and use it in GitHub Desktop.
Save kaloyan-raev/7b216c2a180dde36bac9bc7614bb138c to your computer and use it in GitHub Desktop.
Encryption Access from Encryption Key for Storj V3
package main
import (
"context"
"fmt"
"storj.io/storj/lib/uplink"
)
const (
satelliteAddr = "us-central-1.tardigrade.io:7777"
apiKey = "my-api"
humanReadableKey = "my-human-readable-encryption-key-aka-abc123"
)
func main() {
err := Main(context.Background())
if err != nil {
panic(err)
}
}
func Main(ctx context.Context) error {
ul, err := uplink.NewUplink(ctx, nil)
if err != nil {
return err
}
defer ul.Close()
// Parse the API key. API keys are "macaroons" that allow you to create new, restricted API keys.
key, err := uplink.ParseAPIKey(apiKey)
if err != nil {
return err
}
// Open the project in question. Projects are identified by a specific Satellite and API key
p, err := ul.OpenProject(ctx, satelliteAddr, key)
if err != nil {
return err
}
defer p.Close()
// Make a key
encKey, err := p.SaltedKeyFromPassphrase(ctx, humanReadableKey)
if err != nil {
return err
}
// Make an encryption context
encCtx := uplink.NewEncryptionAccessWithDefaultKey(*encKey)
serialized, err := encCtx.Serialize()
if err != nil {
return err
}
fmt.Println(serialized)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment