RNCryptorNative icon indicating copy to clipboard operation
RNCryptorNative copied to clipboard

Error between android and ios decryption

Open Senemix29 opened this issue 8 years ago • 2 comments
trafficstars

I am using RNCRyptorNative(version 0.0.9) at my android app, which have an iOS(swift) version too. I have a chat which all messages sended are encrypted before save on my database.

When i send messages using android, encrypted by RNCryptorNative, i can't decrypt them on iOS, that uses RNCryptor(https://github.com/RNCryptor/RNCryptor, version 5.0.1) and always get this error:

  • Error decoding text: The operation couldn’t be completed. (RNCryptor.RNCryptor.Error error 2.)

The uncanny problem is that on Android, using your lib, i can decrypt every message that came from an iOS or Android. On Android i am using the default implementation:


private static String encryptMessage(String message, String password) { byte[] encryptedMessage = rncryptor.encrypt(message, password); return new String(encryptedMessage); }


private static String decryptMessage(String encryptedMessage, String password) { return rncryptor.decrypt(encryptedMessage, password); }


This is the following iOS code that are trying to decode android messages without success:


// Encryption func EncryptText(myPassword: String, string: String) -> String { let data = string.data(using: String.Encoding.utf8) let encryptedData = RNCryptor.encrypt(data: data!, withPassword: myPassword) return encryptedData.base64EncodedString(options: NSData.Base64EncodingOptions.init(rawValue: 0)) }


// Decryption func DecryptText(chatRoomID: String, string: String) -> String { let decryptor = RNCryptor.Decryptor(password: chatRoomID) let encryptedData = NSData(base64Encoded: string, options: NSData.Base64DecodingOptions(rawValue: 0)) var message: NSString = "" do { let decryptedData = try decryptor.decrypt(data: encryptedData! as Data)
message = NSString(data: decryptedData, encoding: String.Encoding.utf8.rawValue)! } catch { print("Error decoding text: (error)") } return message as String }


I came with this issue here, because when i use JNCryptor on Android, iOS can decrypt my messages without any problem. I choose to use RNCryptorNative because of the huge performance gain. Can you guys help me with that to try figure out whats happening? Thanks and congrats for the lib!

Senemix29 avatar Aug 02 '17 21:08 Senemix29

Hello @Senemix29 , Were you able to solve this issue? thanks!

giolegaspijr avatar Aug 09 '18 10:08 giolegaspijr

@giolegaspijr i given up on this lib and move foward to another solutions without encryption =/

Senemix29 avatar Aug 25 '18 17:08 Senemix29