-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasher.go
60 lines (56 loc) · 1.38 KB
/
hasher.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
package main
import (
"crypto/aes"
"crypto/sha256"
"encoding/hex"
"fmt"
)
func makehash(text string, keytext string ,plaintexttext string ) bool {
fmt.Println(Warn("hasher running"))
var greenlight = false
var cleaned = clearinput(text)
if cleaned == "1" {
e := Encrypt([]byte(keytext), masterkeyval(clearinput(plaintexttext)))
fmt.Printf("%s\n", e)
greenlight = true
} else {
Decrypt([]byte(keytext), clearinput(plaintexttext))
greenlight = true
}
return greenlight
}
func masterkeyval(cleaned string) string {
if len(cleaned) >= 24 {
return cleaned
}else {
completed := completingstring(cleaned)
return completed
}
}
func Encrypt(key []byte, plaintext string) string {
c, err := aes.NewCipher(key)
if err != nil {
fmt.Errorf(Fata("NewCipher(%d bytes) = %s"), len(key), err)
panic(err)
}
out := make([]byte, len(plaintext))
c.Encrypt(out, []byte(plaintext))
return hex.EncodeToString(out)
}
func Decrypt(key []byte, ct string) {
ciphertext, _ := hex.DecodeString(ct)
c, err := aes.NewCipher(key)
if err != nil {
fmt.Errorf("NewCipher(%d bytes) = %s", len(key), err)
panic(err)
}
plain := make([]byte, len(ciphertext))
c.Decrypt(plain, ciphertext)
s := string(plain[:])
fmt.Printf(Purp("Decrypyed Text: %s\n"), cleanstring(s))
}
func checksum(key string) string {
sha256 := sha256.Sum256([]byte(key))
var keytext = sha256[0:24]
return string(keytext)
}