diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml
new file mode 100644
index 0000000..02b915b
--- /dev/null
+++ b/.idea/git_toolbox_prj.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/go-crypto.iml b/.idea/go-crypto.iml
new file mode 100644
index 0000000..5e764c4
--- /dev/null
+++ b/.idea/go-crypto.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..8d490d6
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..29520ab
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
\ No newline at end of file
diff --git a/crypto.go b/crypto.go
index 661e3c8..583ca6d 100644
--- a/crypto.go
+++ b/crypto.go
@@ -30,7 +30,7 @@ func (crypto CryptoKey) Encrypt(data string) (string, error) {
}
if len(plainText)%aes.BlockSize != 0 {
- err := fmt.Errorf(`plainText: "%s" has the wrong block size`, plainText)
+ err = fmt.Errorf(`plainText: "%s" has the wrong block size`, plainText)
return "", err
}
@@ -41,7 +41,7 @@ func (crypto CryptoKey) Encrypt(data string) (string, error) {
cipherText := make([]byte, aes.BlockSize+len(plainText))
iv := cipherText[:aes.BlockSize]
- if _, err := io.ReadFull(rand.Reader, iv); err != nil {
+ if _, err = io.ReadFull(rand.Reader, iv); err != nil {
return "", err
}
@@ -63,7 +63,10 @@ func (crypto CryptoKey) Decrypt(encrypted string) (string, error) {
encrypted = split[0] + split[1]
- cipherText, _ := hex.DecodeString(encrypted)
+ cipherText, err := hex.DecodeString(encrypted)
+ if err != nil {
+ return "", err
+ }
block, err := aes.NewCipher(crypto.key)
if err != nil {
@@ -83,7 +86,10 @@ func (crypto CryptoKey) Decrypt(encrypted string) (string, error) {
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(cipherText, cipherText)
- cipherText, _ = pkcs7.Unpad(cipherText, aes.BlockSize)
+ cipherText, err = pkcs7.Unpad(cipherText, aes.BlockSize)
+ if err != nil {
+ return "", err
+ }
return string(cipherText), nil
}