RNCryptor/RNCryptor

RNCryptor.DecryptorV3 error with flutter

rulefahd opened this issue · 6 comments

when I try to use decryptor3 on dart and iOS , it won't work

dart= RNCryptor.encryptWithKey(Uint8List(16), Uint8List(16), message);

swift = try RNCryptor.DecryptorV3(encryptionKey: Data(count: 16), hmacKey: Data(count: 16)).decrypt(data: data!)

error : RNCryptor/RNCryptor.swift:416: Precondition failed
2022-06-20 14:25:51.413322+0200 chat[11840:856203] RNCryptor/RNCryptor.swift:416: Precondition failed

You're passing 16 bytes of zeros as your key (why all zeros?). AES-256 requires a 32-byte key:

https://github.com/RNCryptor/RNCryptor/blob/master/Sources/RNCryptor/RNCryptor.swift#L416

You're passing 16 bytes of zeros as your key (why all zeros?). AES-256 requires a 32-byte key:

https://github.com/RNCryptor/RNCryptor/blob/master/Sources/RNCryptor/RNCryptor.swift#L416

Can you explain by an example of should be done on flutter and swift to work fine?

I have tried it locally on dart it works fine(encrypt and decrypt) but when I decrypt it on flutter and decrypt it on swift, it gives that error

@rnapier
If you mean on swift code, how can i use the same key of Uint8List(xx) there? To decrypt it correctly?

I have done very little work in Dart. If you can show your working Dart code, I can likely explain what your problem is. Do note that encryptWithKey is an advanced method, and relies on you having a good understanding of cryptography primitives to use correctly. Generally you should be using the password form. Why are you using the key form? Do make sure to read the FAQ about general formats: https://github.com/RNCryptor/RNCryptor#can-i-use-rncryptor-to-read-and-write-my-non-rncryptor-data-format

I have done very little work in Dart. If you can show your working Dart code, I can likely explain what your problem is. Do note that encryptWithKey is an advanced method, and relies on you having a good understanding of cryptography primitives to use correctly. Generally you should be using the password form. Why are you using the key form? Do make sure to read the FAQ about general formats: https://github.com/RNCryptor/RNCryptor#can-i-use-rncryptor-to-read-and-write-my-non-rncryptor-data-format

The app I'm building is chat app, the password method has delay of 1-3 secs, which is not ideal

So I want to use a faster method of encrypting in dart and decrypting in swift ( same string)

1-3 seconds is very surprising. It should be about 100ms if you’re just performing a single encryption. For advanced usage, key-based encryption is faster for repeated encryptions, but you must be extremely careful to use it correctly. It is called "advanced" for a reason. If you're unfamiliar with how to work with raw data, you'll need to study that first. For details, see https://github.com/RNCryptor/RNCryptor#key-based-encryption

If performance is a significant concern, I would recommend performing more of the operations in Swift, and just pass the results back to Dart. Crossing the bridge is not free.