-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextractHash.go
53 lines (43 loc) · 1.15 KB
/
extractHash.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
package main
import (
"encoding/hex"
"strings"
)
func detectHash(data string) int {
switch {
case data == "MD5":
return MD5RAW
case data == "MD5spSHA1sp":
return MD5SaltPreSHA1SaltPre
default:
return UNKNOWN
}
}
func extractTokens(hashType int, data string) Hash {
switch hashType {
case MD5RAW:
return extractMD5RAW(data)
case MD5SaltPreSHA1SaltPre:
return extractMD5SaltPreSHA1SaltPre(data)
default:
return Hash{[]byte(""), SaltList{}, UNKNOWN, "", ""}
}
}
func extractMD5RAW(data string) Hash {
split := strings.Split(data, ":")
encodedHash := split[1]
decodedHash, err := hex.DecodeString(encodedHash)
check(err)
hash := Hash{decodedHash, SaltList{}, MD5RAW, "", ""}
return hash
}
func extractMD5SaltPreSHA1SaltPre(data string) Hash {
// md5(salt1.sha1(salt2.password)) with upper hex output for sha1 hash
// Salts are taken from the outer layer to the inner one, e.g. type:hash:salt1:salt2
split := strings.Split(data, ":")
encodedHash := split[1]
decodedHash, err := hex.DecodeString(encodedHash)
check(err)
hash := Hash{decodedHash, SaltList{Salt(split[2]), Salt(split[3])}, MD5SaltPreSHA1SaltPre, "", ""}
return hash
}