Last active
July 18, 2019 16:03
-
-
Save kaloyan-raev/7b216c2a180dde36bac9bc7614bb138c to your computer and use it in GitHub Desktop.
Encryption Access from Encryption Key for Storj V3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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