Skip to content

Instantly share code, notes, and snippets.

@kaloyan-raev kaloyan-raev/main.go
Last active Jul 18, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.