mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-28 04:49:33 +02:00
@@ -101,8 +101,17 @@ func Decrypt(content string, key []byte) (string, error) {
|
|||||||
mode.CryptBlocks(plaintext, ciphertext)
|
mode.CryptBlocks(plaintext, ciphertext)
|
||||||
|
|
||||||
// remove padding
|
// remove padding
|
||||||
padding := int(plaintext[len(plaintext)-1]) // the padding amount is encoded in the padding bytes themselves
|
var (
|
||||||
message := string(plaintext[0 : len(plaintext)-padding])
|
message = string(plaintext)
|
||||||
|
plaintextLen = len(plaintext)
|
||||||
|
)
|
||||||
|
if plaintextLen > 0 {
|
||||||
|
padding := int(plaintext[plaintextLen-1]) // the padding amount is encoded in the padding bytes themselves
|
||||||
|
if padding > plaintextLen {
|
||||||
|
return "", fmt.Errorf("Invalid padding amount: %d. \n", padding)
|
||||||
|
}
|
||||||
|
message = string(plaintext[0 : plaintextLen-padding])
|
||||||
|
}
|
||||||
|
|
||||||
return message, nil
|
return message, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user