-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
73 lines (72 loc) · 2.14 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Chainify Group LTD. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package sdk is the Unofficial Go SDK implementation of the AWS Encryption SDK.
//
// # Getting started
//
// To install the AWS Encryption SDK for Go, use the following command:
//
// go get github.com/chainifynet/aws-encryption-sdk-go@latest
//
// # Usage
//
// The following example demonstrates how to use SDK to encrypt and decrypt data using a static key.
//
// package main
//
// import (
// "context"
// "fmt"
//
// "github.com/chainifynet/aws-encryption-sdk-go/pkg/client"
// "github.com/chainifynet/aws-encryption-sdk-go/pkg/materials"
// "github.com/chainifynet/aws-encryption-sdk-go/pkg/providers/rawprovider"
// )
//
// func main() {
// // static key to use for encryption and decryption
// staticKey1 := []byte("superSecureKeySecureKey32bytes32")
//
// // data to encrypt
// secretData := []byte("secret data to encrypt")
//
// // setup Encryption SDK client with default configuration
// sdkClient := client.NewClient()
//
// // setup Raw Key provider
// rawKeyProvider, err := rawprovider.NewWithOpts(
// "raw",
// rawprovider.WithStaticKey("static1", staticKey1),
// )
// if err != nil {
// panic(err) // handle error
// }
//
// // setup crypto materials manager
// cmm, err := materials.NewDefault(rawKeyProvider)
// if err != nil {
// panic(err) // handle error
// }
//
// // encrypt data without encryption context passing nil as the third argument
// encrypted, header, err := sdkClient.Encrypt(context.TODO(), secretData, nil, cmm)
// if err != nil {
// panic(err) // handle error
// }
//
// fmt.Printf("encrypted encryption context: %v\n", header.AADData().EncryptionContext())
//
// // decrypt "encrypted" data
// decrypted, _, err := sdkClient.Decrypt(context.TODO(), encrypted, cmm)
// if err != nil {
// panic(err) // handle error
// }
//
// fmt.Printf("decrypted data: %s\n", decrypted)
//
// // verify that "decrypted" plaintext is identical to the original secret data
// if string(decrypted) != string(secretData) {
// panic("decrypted data does not match with the original data")
// }
// }
package sdk