Skip to content

Commit c836d1c

Browse files
committed
release encryption
1 parent 41a3a23 commit c836d1c

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Synology Cloud Sync decryption in Go
1+
# Synology Cloud Sync encryption/decryption in Go
22

33
[![GoDoc](https://godoc.org/github.com/maxlaverse/synocrypto?status.svg)](https://godoc.org/github.com/maxlaverse/synocrypto)
44
[![test](https://github.com/maxlaverse/synocrypto/actions/workflows/workflow.yaml/badge.svg)](https://github.com/maxlaverse/synocrypto/actions/workflows/workflow.yaml)
@@ -45,7 +45,7 @@ GLOBAL OPTIONS:
4545

4646
## Library
4747

48-
### Usage
48+
### Decryption Usage
4949

5050
```go
5151
encFile, err := os.Open("./my-encrypted-file.jpg")
@@ -70,18 +70,36 @@ if err != nil {
7070
}
7171
```
7272

73-
### Encryption Support
73+
### Encryption Usage
7474

75-
The library has a prototype implementation for encrypting files.
76-
Files encrypted with it can often (always?) be decrypted using the library again.
77-
However, Cloudsync sometimes fails to decrypt them with errors related to compression:
78-
```
79-
Sep 16 22:54:25 [ERROR] lz4-processor.cpp(239): LZ4F_decompress LOGIC ERROR: inbuf_consumed='0' inbuf_size='8'
80-
Sep 16 22:54:25 [ERROR] pipeline.cpp(119): Failed when read
81-
Sep 16 22:54:25 [ERROR] encrypt-file.cpp(148): Failed when reading from decryptor.
82-
Sep 16 22:54:25 [WARNING] worker.cpp(3211): Worker (15): Failed to decrypt file
75+
```go
76+
plainFile, err := os.Open("./my-plain-file.jpg")
77+
if err != nil {
78+
panic(err)
79+
}
80+
defer plainFile.Close()
81+
82+
encFile, err := os.OpenFile("./my-encrypted-file.jpg", os.O_CREATE|os.O_WRONLY, 0644)
83+
if err != nil {
84+
panic(err)
85+
}
86+
defer encFile.Close()
87+
88+
privateKey, err := ioutil.ReadFile("private.pem")
89+
if err != nil {
90+
panic(err)
91+
}
92+
93+
encrypter := synocrypto.NewEncrypter(synocrypto.EncrypterOptions{
94+
Password: "synocrypto",
95+
PrivateKey: privateKey,
96+
})
97+
98+
err = encrypter.Encrypt(plainFile, encFile)
99+
if err != nil {
100+
panic(err)
101+
}
83102
```
84103

85-
I haven't had the time to debug this further.
86104

87105
[releases]: https://github.com/maxlaverse/synocrypto/releases

synocrypto_encrypter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func (e *encrypter) encrypt(in io.Reader, out io.Writer) error {
104104
metadata[encoding.MetadataFieldEncryptionKey2Hash] = privateKeyEncryptedSessionKeyHash
105105
}
106106

107+
if len(e.options.Password) == 0 || len(e.options.PrivateKey) == 0 {
108+
log.Warning("Both password and private key are required in order for CloudSync to decrypt the data")
109+
}
110+
107111
if e.options.Filename != "" {
108112
metadata[encoding.MetadataFieldFilename] = path.Base(e.options.Filename)
109113
}
@@ -129,6 +133,7 @@ func (e *encrypter) encrypt(in io.Reader, out io.Writer) error {
129133
in, err = compression.NewLz4CompExternal(in)
130134
} else {
131135
log.Debug("Using builtin lz4 compressor")
136+
log.Warning("The built-in lz4 compressor produces files which can be read only by this library, not CloudSync")
132137
in, err = compression.NewLz4CompBuiltin(in)
133138
}
134139
if err != nil {

0 commit comments

Comments
 (0)