rust-nostr / nostr

Nostr protocol implementation, SDK and FFI
https://rust-nostr.org/
MIT License
417 stars 90 forks source link

Wrong encryption block mode. The content must be encrypted using CBC mode! #180

Closed frbitten closed 1 year ago

frbitten commented 1 year ago

Hi

I'm trying to make a bot via private messages and when I receive a message and try to decrypt it I get the error below:

Error during content decryption: err='Wrong encryption block mode. The content must be encrypted using CBC mode!'

I use the nostr-sdk package in Python. Does anyone have any suggestions as to what I'm doing wrong in the process? I'm trying the example: https://github.com/rust-nostr/nostr/blob/master/bindings/nostr-sdk-ffi/bindings-python/examples/bot.py

yukibtc commented 1 year ago

Are you encrypting the message with the nostr-sdk?

frbitten commented 1 year ago

No. I send a private message from my Amethyst account to the public key on the bot.

w3irdrobot commented 1 year ago

for reference, this appears to be the code for amethyst's nip04 encryption: https://github.com/vitorpamplona/amethyst/blob/4f4cab6a6c4053c85b65b8ca4dcf4d5ab5f320f1/quartz/src/main/java/com/vitorpamplona/quartz/crypto/CryptoUtils.kt#L66-L89

frbitten commented 1 year ago

I found the problem. The filter was wrong and I was trying to read a message from the same author but it was not the same recipient. Therefore, the key was invalid for encryption.