Improved decryption error messages

This commit is contained in:
2025-05-03 17:17:14 -04:00
parent 84bd8c3a42
commit b93acdcaef
+3 -3
View File
@@ -2,8 +2,8 @@ package wrappers
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"io" "io"
"log"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
) )
@@ -45,7 +45,7 @@ func EncryptCha(data []byte, passphrase []byte) []byte {
// DecryptCha decrypts data using ChaCha20-Poly1305 // DecryptCha decrypts data using ChaCha20-Poly1305
func DecryptCha(encryptedData []byte, passphrase []byte) []byte { func DecryptCha(encryptedData []byte, passphrase []byte) []byte {
if len(encryptedData) < saltSizeCha+nonceSizeCha { if len(encryptedData) < saltSizeCha+nonceSizeCha {
log.Fatalf("encrypted data is too short") fmt.Println("Encrypted data is too short")
return nil return nil
} }
@@ -63,7 +63,7 @@ func DecryptCha(encryptedData []byte, passphrase []byte) []byte {
// decrypt the data // decrypt the data
plaintext, err := aead.Open(nil, nonce, ciphertext, nil) plaintext, err := aead.Open(nil, nonce, ciphertext, nil)
if err != nil { if err != nil {
log.Fatalf("decryption failed (possibly wrong passphrase): %w", err) fmt.Printf("Decryption failed (possibly wrong passphrase): %s", err.Error())
return nil return nil
} }