-
Notifications
You must be signed in to change notification settings - Fork 6
/
crypt_windows.go
46 lines (40 loc) · 886 Bytes
/
crypt_windows.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
45
46
package main
/*
#cgo LDFLAGS: -lCrypt32
#define NOMINMAX
#include <windows.h>
#include <Wincrypt.h>
char* decrypt(byte* in, int len, int *outLen) {
DATA_BLOB input, output;
LPWSTR pDescrOut = NULL;
input.cbData = len;
input.pbData = in;
CryptUnprotectData(
&input,
&pDescrOut,
NULL, // Optional entropy
NULL, // Reserved
NULL, // Here, the optional
// prompt structure is not
// used.
0,
&output);
*outLen = output.cbData;
return output.pbData;
}
void doFree(char* ptr) {
free(ptr);
}
*/
import "C"
type WindowsCrypt struct {
}
func NewCrypt() crypt {
return &WindowsCrypt{}
}
func (c *WindowsCrypt) decrypt(input []byte) string {
var length C.int
decruptedC := C.decrypt((*C.byte)(&input[0]), C.int(len(input)), &length)
decrypted := C.GoStringN(decruptedC, length)
return decrypted
}