mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-16 22:42:19 +02:00
fix: nip04 remove extra padding
This commit is contained in:
committed by
fiatjaf
parent
6aab32ef4f
commit
3f2c3f1bd8
@ -8,7 +8,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
mrand "math/rand"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
@ -56,18 +55,12 @@ func Encrypt(message string, key []byte) (string, error) {
|
|||||||
|
|
||||||
// add padding
|
// add padding
|
||||||
base := len(plaintext)
|
base := len(plaintext)
|
||||||
extra := 0
|
|
||||||
var padding int
|
|
||||||
if base < 100 {
|
|
||||||
// add some random padding to this message since it is too small
|
|
||||||
extra = mrand.Intn(230) // the total padding will be padding + extra, which can't be more than 256
|
|
||||||
}
|
|
||||||
|
|
||||||
// this will be a number between 1 and 16 (including), never 0
|
// this will be a number between 1 and 16 (including), never 0
|
||||||
padding = block.BlockSize() - (base+extra)%block.BlockSize()
|
padding := block.BlockSize() - base%block.BlockSize()
|
||||||
|
|
||||||
// encode the padding in all the padding bytes themselves
|
// encode the padding in all the padding bytes themselves
|
||||||
padtext := bytes.Repeat([]byte{byte(padding + extra)}, padding+extra)
|
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||||
|
|
||||||
paddedMsgBytes := append(plaintext, padtext...)
|
paddedMsgBytes := append(plaintext, padtext...)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user