summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorLevi Durfee <levi.durfee@gmail.com>2026-01-06 18:16:32 -0500
committerLevi Durfee <levi.durfee@gmail.com>2026-01-06 18:16:34 -0500
commitd1ba4cc661f8d15c33e051f21ce6ff69ed2fc687 (patch)
tree3d669421dd20616f3ede6933c2ace7d3b8e4a1a1 /main.go
parent6630c8cb513941b4bb2f0a24f23143665f4b9476 (diff)
Encode encrypted dek and ciphertext in a binary
and write to file
Diffstat (limited to 'main.go')
-rw-r--r--main.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.go b/main.go
index e93d2a3..79bd45f 100644
--- a/main.go
+++ b/main.go
@@ -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 {