浏览代码

add debug log for decrypt message

Max Ma 1 年之前
父节点
当前提交
76e2af7c84
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      netclient/ncutils/encryption.go

+ 4 - 1
netclient/ncutils/encryption.go

@@ -7,6 +7,7 @@ import (
 	"io"
 
 	"golang.org/x/crypto/nacl/box"
+	"golang.org/x/exp/slog"
 )
 
 const (
@@ -28,8 +29,10 @@ func BoxEncrypt(message []byte, recipientPubKey *[32]byte, senderPrivateKey *[32
 func BoxDecrypt(encrypted []byte, senderPublicKey *[32]byte, recipientPrivateKey *[32]byte) ([]byte, error) {
 	var decryptNonce [24]byte
 	copy(decryptNonce[:], encrypted[:24])
-	decrypted, ok := box.Open(nil, encrypted[24:], &decryptNonce, senderPublicKey, recipientPrivateKey)
+	out := []byte{}
+	decrypted, ok := box.Open(out, encrypted[24:], &decryptNonce, senderPublicKey, recipientPrivateKey)
 	if !ok {
+		slog.Debug("could not decrypt message", "out", out)
 		return nil, fmt.Errorf("could not decrypt message, %v", encrypted)
 	}
 	return decrypted, nil