-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
62 lines (54 loc) · 1.43 KB
/
generator.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package goinsta
import (
"crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
)
const (
volatileSeed = "12345"
)
func generateMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func generateHMAC(text, key string) string {
hasher := hmac.New(sha256.New, []byte(key))
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func generateDeviceID(seed string) string {
hash := generateMD5Hash(seed + volatileSeed)
return "android-" + hash[:16]
}
func newUUID() (string, error) {
uuid := make([]byte, 16)
n, err := io.ReadFull(rand.Reader, uuid)
if n != len(uuid) || err != nil {
return "", err
}
// variant bits; see section 4.1.1
uuid[8] = uuid[8]&^0xc0 | 0x80
// version 4 (pseudo-random); see section 4.1.3
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
}
func generateUUID() string {
uuid, err := newUUID()
if err != nil {
return "cb479ee7-a50d-49e7-8b7b-60cc1a105e22" // default value when error occurred
}
return uuid
}
func generateSignature(data string) map[string]string {
m := make(map[string]string)
m["ig_sig_key_version"] = goInstaSigKeyVersion
m["signed_body"] = fmt.Sprintf(
"%s.%s", generateHMAC(data, goInstaIGSigKey), data,
)
return m
}