-
Notifications
You must be signed in to change notification settings - Fork 0
/
radius-crypt.go
61 lines (56 loc) · 1.52 KB
/
radius-crypt.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
/*
* GPLv3
* Crypt for Radius
* https://freeradius.org/radiusd/man/rlm_pap.html
*
*/
package main
import (
"crypto/md5"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"fmt"
"math/rand"
"os"
"strings"
"time"
)
//VERSION of this script
const VERSION string = "1.0"
func getSalt(length int) string {
rand.Seed(time.Now().UnixNano())
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"0123456789" +
"-_")
var b strings.Builder
for i := 0; i < length; i++ {
b.WriteRune(chars[rand.Intn(len(chars))])
}
return string(b.String())
}
func main() {
salt := getSalt(20)
if len(os.Args) != 2 {
fmt.Println("Usage:", os.Args[0], "PASSWORD")
fmt.Println("Please insert only one password.")
os.Exit(1)
}
pw := os.Args[1]
md5 := md5.New()
sha256 := sha256.New()
sha512 := sha512.New()
pw = pw + salt
md5.Write([]byte(string(pw)))
sha256.Write([]byte(string(pw)))
sha512.Write([]byte(string(pw)))
rMd5 := md5.Sum(nil)
rSha256 := sha256.Sum(nil)
rSha512 := sha512.Sum(nil)
fmt.Println("Version:", VERSION)
fmt.Println("Salt:", salt)
fmt.Println("{SMD5-Password}:", base64.StdEncoding.EncodeToString(append(rMd5, []byte(salt)...)))
fmt.Println("{SSHA2-256-Password}:", base64.StdEncoding.EncodeToString(append(rSha256, []byte(salt)...)))
fmt.Println("{SSHA2-512-Password}:", base64.StdEncoding.EncodeToString(append(rSha512, []byte(salt)...)))
}