-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcrypto.go
executable file
·55 lines (42 loc) · 1.07 KB
/
crypto.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
package cryptocmds
import (
"dfis-utils/pkg/cryptoutils"
"errors"
"os"
"github.com/ibraimgm/libcmd"
)
// CryptoHash function generates cryptographically secure hashes for small & big files
func CryptoHash(cmd *libcmd.Cmd) error {
small := cmd.GetBool("small")
file := cmd.Operand("FILE")
if file == "" {
return errors.New("you must specify the FILE to hash")
}
if _, err := os.Stat(file); err != nil {
return err
}
if *small {
return cryptoutils.Smallhash(file)
}
return cryptoutils.Bighash(file)
}
// CryptoHMAC function convert plain-text passwords into HMAC secure ones
func CryptoHMAC(cmd *libcmd.Cmd) error {
input := cmd.Operand("INPUT")
if input == "" {
return errors.New("you must specify an INPUT text to hash")
}
cryptoutils.Passtore(input)
return nil
}
// CryptoAES encrypts files using AES-CFB method
func CryptoAES(cmd *libcmd.Cmd) error {
file := cmd.Operand("FILE")
if file == "" {
return errors.New("you must specify the FILE to cypher")
}
if _, err := os.Stat(file); err != nil {
return err
}
return cryptoutils.Adves(file)
}