-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.go
44 lines (37 loc) · 682 Bytes
/
decrypt.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
package algorithm
import (
"fmt"
"os"
"sync"
"github.com/unidoc/unipdf/v3/model"
)
func DecryptPdf(filePath string, passChannel chan string, wg *sync.WaitGroup) error {
f, err := os.Open(filePath)
if err != nil {
return err
}
defer f.Close()
pdfReader, err := model.NewPdfReader(f)
if err != nil {
return err
}
isEncrypted, err := pdfReader.IsEncrypted()
if err != nil {
return err
}
if isEncrypted {
for password := range passChannel {
auth, err := pdfReader.Decrypt([]byte(password))
if err != nil {
return err
}
if auth {
fmt.Println(password)
wg.Done()
} else {
fmt.Errorf("Wrong password")
}
}
}
return nil
}