@@ -2,20 +2,17 @@ package helper
22
33import (
44 "bufio"
5- "bytes"
65 "crypto/aes"
76 "crypto/cipher"
87 "crypto/des"
98 "crypto/hmac"
109 "crypto/rand"
1110 "crypto/sha256"
1211 "crypto/sha512"
13- "encoding/base64"
1412 "errors"
1513 "golang.org/x/crypto/pbkdf2"
1614 "hash"
1715 "io"
18- "log"
1916 "os"
2017 "strings"
2118)
@@ -130,16 +127,6 @@ func Encryption(password string, plainText string, cli Parameters, meta Metadata
130127
131128}
132129
133- func encodeBase64 (input []byte ) string {
134- return base64 .StdEncoding .EncodeToString (input )
135- }
136-
137- func DecodeBase64 (input string ) []byte {
138- str , err := base64 .StdEncoding .DecodeString (input )
139- CheckError (err )
140- return str
141- }
142-
143130/*
144131This function will take in the encrypted file path and the password from the user.
145132The rest of the parameters required for decryptio, will be extracted from the metadata, written during the encryption process
@@ -258,40 +245,3 @@ func Decryption(file string, password string) (text string, err error) {
258245
259246 return string (unpadText ), err
260247}
261-
262- //Function to check errors, to prevent a lot if statements in-code
263- func CheckError (err error ) {
264- if err != nil {
265- log .Fatal (err )
266- //panic(err)
267- }
268- }
269-
270- //Function to pad the data and figure out the block size by repeating the bytes
271- func Pad (src []byte , algorithm string ) []byte {
272- var padding int
273-
274- if (algorithm == "aes128" ) || algorithm == "aes256" {
275- padding = aes .BlockSize - len (src )% aes .BlockSize
276- } else if algorithm == "3des" {
277- padding = des .BlockSize - len (src )% des .BlockSize
278- } else {
279- err := errors .New ("invalid encryption choice" )
280- CheckError (err )
281- }
282-
283- padtext := bytes .Repeat ([]byte {byte (padding )}, padding )
284- return append (src , padtext ... )
285- }
286-
287- //Function to unpad the data
288- func Unpad (src []byte ) ([]byte , error ) {
289- length := len (src )
290- unpadding := int (src [length - 1 ])
291-
292- if unpadding > length {
293- return nil , errors .New ("un-padding error. " )
294- }
295-
296- return src [:(length - unpadding )], nil
297- }
0 commit comments