diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,10 +1,12 @@ package main import ( + "bytes" "crypto/aes" "crypto/cipher" "crypto/rand" "encoding/base64" + "encoding/gob" "errors" "fmt" "io" @@ -21,6 +23,11 @@ type ( Ciphertext []byte ) +type EncryptedDataPayload struct { + DEK WrappedDEK + Payload Ciphertext +} + var ( aadWrapDEK = []byte("wrap:dek:v1") aadDataMsg = []byte("data:msg:v1") @@ -56,6 +63,18 @@ func main() { fmt.Println("edek_b64:", base64.StdEncoding.EncodeToString(edek)) fmt.Println("ct_b64: ", base64.StdEncoding.EncodeToString(ct)) + var dataBuffer bytes.Buffer + enc := gob.NewEncoder(&dataBuffer) + + err = enc.Encode(EncryptedDataPayload{ + DEK: edek, + Payload: ct, + }) + + fmt.Println(dataBuffer) + + os.WriteFile("out.bin", dataBuffer.Bytes(), 0666) + // Round-trip demo. dek2, err := UnwrapDEK(edek, kek) if err != nil { |
