-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwin.go
More file actions
34 lines (26 loc) · 734 Bytes
/
win.go
File metadata and controls
34 lines (26 loc) · 734 Bytes
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
package main
import (
"fmt"
"unsafe"
"golang.org/x/sys/windows"
)
func bytesToBlob(bytes []byte) *windows.DataBlob {
blob := &windows.DataBlob{Size: uint32(len(bytes))}
if len(bytes) > 0 {
blob.Data = &bytes[0]
}
return blob
}
func Decrypt(data []byte) ([]byte, error) {
out := windows.DataBlob{}
var outName *uint16
err := windows.CryptUnprotectData(bytesToBlob(data), &outName, nil, 0, nil, 0, &out)
if err != nil {
return nil, fmt.Errorf("unable to decrypt DPAPI protected data: %w", err)
}
ret := make([]byte, out.Size)
copy(ret, unsafe.Slice(out.Data, out.Size))
windows.LocalFree(windows.Handle(unsafe.Pointer(out.Data)))
windows.LocalFree(windows.Handle(unsafe.Pointer(outName)))
return ret, nil
}