shyandsy / cipher2

a flutter plugin for AES encryption and decryption
GNU General Public License v3.0
43 stars 40 forks source link

On iOS, the decrypted String equals the iOS software version #1

Closed Peter-717 closed 5 years ago

Peter-717 commented 5 years ago

On iOS, the decrypted returned string is the iOS version of the iPhone. Like iOS 10.3.3 Works fine on Android. It seems that the plugin is based on swift 2.0. Might be the problem. Could you please update the plugin to be Swift 4.2 compatible? Thanks

shyandsy commented 5 years ago

hi,

thanks for using my plugin.

unfortunately, there is no implementation for ios right now due to the fact i dont have Mac computer for the ios programming.

that will be done before Feb 10, is that ok for you?

Peter-717 commented 5 years ago

Yes, that's fine. Please let me know if I can be of any assistance (I am using a Mac). I will gladly test your code as soon as possible. Mid-February is really a deadline for me. Thanks again for your quick reply.

shyandsy commented 5 years ago

en, there is no any MAC computer on my hand right now

i will try to borrow one and done that as soon as possible

just give me a star after i done that part, thanks:smile:

Peter-717 commented 5 years ago

I will gladly report when it works on iOS and give you a BIG star!

Peter-717 commented 5 years ago

Have you checked: https://github.com/krzyzanowskim/CryptoSwift Please look at their AES example, it sounds like a swift call like the one that follows could be the answer. What do you think? let decrypted = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7).decrypt(encrypted)

shyandsy commented 5 years ago

@Peter-717

I created a macos system on vmware yesterday, and finished the ios support today.

it works now, just try it

Peter-717 commented 5 years ago

Thank you so much.

Excuse my lack of knowledge. But how do import the CryptoSwift Library?

I get a “No such module CryptoSwift” in Xcode when running the code.

THANKS!!!

On Jan 22, 2019, at 2:45 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 I created a macos system on vmware yesterday, and finished the ios support today.

it works now, just try it

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456575608, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MSa4Wp4evtrzRT-PUaGA-vH2cFX4ks5vF4aPgaJpZM4aJb65.

Peter-717 commented 5 years ago

Got it to work by doing the following:

Peter-717 commented 5 years ago

Just noticed that the App will crash if the decrypted provided string isn't of 24 characters exactly.

Peter-717 commented 5 years ago

Actually a bit worse than that. If the decryption fails (for any reason), the App crashes silently (no error is thrown)

shyandsy commented 5 years ago

@Peter-717 the exmaple code in the plugin works good on my machine

could u give a sample input for crash?

for now, i haven't do input data validate in the plugin, and you have to check the input data before call the method. i will add the validation code later

shyandsy commented 5 years ago

@Peter-717 en, it should add CryptoSwift Library by itself

why u need to add CryptoSwift Library>?

Peter-717 commented 5 years ago

The code works good on my machine too, when the string to be decrypted is a “valid” encrypted string.

As soon as you provide any other string like ‘Hello’ for being decrypted, the App crashes silently :( no error message printed on the console.

On Jan 22, 2019, at 7:57 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 the exmaple code in the plugin works good on my machine

could u give a sample input for crash?

for now, i haven't do input data validate in the plugin, and you have to check the input data before call the method. i will add the validation code later

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456650303, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MdENIGvNskz5IlAMXQ-q1XbDTXIwks5vF8-ZgaJpZM4aJb65.

Peter-717 commented 5 years ago

Please try to run the following code: class _MyHomePageState extends State {

String plainText = '我是shyandsy,never give up man'; String key = 'xxxxxxxxxxxxxxxx'; String iv = 'yyyyyyyyyyyyyyyy';

String encryptedString;

String decryptedString;

@override void initState() { // TODO: implement initState super.initState(); _encrypt(); }

Future _encrypt() async { encryptedString = await Cipher2.encryptAesCbc128Padding7(plainText, key, iv); print(encryptedString); }

Future _decrypt() async {

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString);
encryptedString = 'Hello';

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString);

}

The App crashes as soon as it tries to decrypt the string 'Hello'. Hope this helps. Thanks!

shyandsy commented 5 years ago

obviously hello is not a valid encrypted string

its aes 128 pkcs padding 7, u should pass a base64 encode string with n times 128bit length

发自我的 iPhone

在 2019年1月22日,21:06,Peter-717 notifications@github.com 写道:

The code works good on my machine too, when the string to be decrypted is a “valid” encrypted string.

As soon as you provide any other string like ‘Hello’ for being decrypted, the App crashes silently :( no error message printed on the console.

On Jan 22, 2019, at 7:57 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 the exmaple code in the plugin works good on my machine

could u give a sample input for crash?

for now, i haven't do input data validate in the plugin, and you have to check the input data before call the method. i will add the validation code later

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456650303, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MdENIGvNskz5IlAMXQ-q1XbDTXIwks5vF8-ZgaJpZM4aJb65.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Peter-717 commented 5 years ago

I agree with you, but the problem is that you can not know in advance whether the String you’re provided with meets these criteria. On the Android side, if you provide ‘Hello’ to the Decrypter method, it rightly returns an error, but doesn’t crash the app.

On Jan 22, 2019, at 9:10 PM, shyandsy notifications@github.com wrote:

obviously hello is not a valid encrypted string

its aes 128 pkcs padding 7, u should pass a base64 encode string with n times 128bit length

发自我的 iPhone

在 2019年1月22日,21:06,Peter-717 notifications@github.com 写道:

The code works good on my machine too, when the string to be decrypted is a “valid” encrypted string.

As soon as you provide any other string like ‘Hello’ for being decrypted, the App crashes silently :( no error message printed on the console.

On Jan 22, 2019, at 7:57 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 the exmaple code in the plugin works good on my machine

could u give a sample input for crash?

for now, i haven't do input data validate in the plugin, and you have to check the input data before call the method. i will add the validation code later

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456650303, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MdENIGvNskz5IlAMXQ-q1XbDTXIwks5vF8-ZgaJpZM4aJb65.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456663201, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MRDdQuzJu-a3kIVSYhSh3UAaDRnGks5vF-CjgaJpZM4aJb65.

shyandsy commented 5 years ago

i agree with u and i will add input check later

发自我的 iPhone

在 2019年1月22日,21:48,Peter-717 notifications@github.com 写道:

Please try to run the following code: class _MyHomePageState extends State {

String plainText = '我是shyandsy,never give up man'; String key = 'xxxxxxxxxxxxxxxx'; String iv = 'yyyyyyyyyyyyyyyy';

String encryptedString;

String decryptedString;

@override void initState() { // TODO: implement initState super.initState(); _encrypt(); }

Future _encrypt() async { encryptedString = await Cipher2.encryptAesCbc128Padding7(plainText, key, iv); print(encryptedString); }

Future _decrypt() async {

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString); encryptedString = 'Hello';

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString); }

The App crashes as soon as it tries to decrypt the string 'Hello'. Hope this helps. Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Peter-717 commented 5 years ago

Thanks! Can’t wait - We’re so close now :)

On Jan 22, 2019, at 9:59 PM, shyandsy notifications@github.com wrote:

i agree with u and i will add input check later

发自我的 iPhone

在 2019年1月22日,21:48,Peter-717 notifications@github.com 写道:

Please try to run the following code: class _MyHomePageState extends State {

String plainText = '我是shyandsy,never give up man'; String key = 'xxxxxxxxxxxxxxxx'; String iv = 'yyyyyyyyyyyyyyyy';

String encryptedString;

String decryptedString;

@override void initState() { // TODO: implement initState super.initState(); _encrypt(); }

Future _encrypt() async { encryptedString = await Cipher2.encryptAesCbc128Padding7(plainText, key, iv); print(encryptedString); }

Future _decrypt() async {

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString); encryptedString = 'Hello';

decryptedString = await Cipher2.decryptAesCbc128Padding7(encryptedString, key, iv);

print(decryptedString); }

The App crashes as soon as it tries to decrypt the string 'Hello'. Hope this helps. Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-456670794, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-Me5pai2PbdF7o1V8OSp5NOxtTqWwks5vF-wpgaJpZM4aJb65.

shyandsy commented 5 years ago

@Peter-717 the new version 0.2.0 published

the exception can be handled for both ios and android

https://pub.dartlang.org/packages/cipher2

Peter-717 commented 5 years ago

Awesome! I’ll give it a try tomorrow. Thanks!

On Jan 23, 2019, at 4:26 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 the new version 0.2.0 published

the exception can be handled for both ios and android

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-457006373, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MbYlIyI8m-wAJzrCT724gcI0PyQrks5vGO-JgaJpZM4aJb65.

shyandsy commented 5 years ago

welcome

i also need this code for my project

and i will support the other mode of aes, and other encryption method later

发自我的 iPhone

在 2019年1月23日,22:08,Peter-717 notifications@github.com 写道:

Awesome! I’ll give it a try tomorrow. Thanks!

On Jan 23, 2019, at 4:26 PM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 the new version 0.2.0 published

the exception can be handled for both ios and android

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-457006373, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MbYlIyI8m-wAJzrCT724gcI0PyQrks5vGO-JgaJpZM4aJb65.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

shyandsy commented 5 years ago

@Peter-717 any feedback?

Peter-717 commented 5 years ago

Works great now on both iOS and Android - Thanks!

On Jan 31, 2019, at 12:25 AM, shyandsy notifications@github.com wrote:

@Peter-717 https://github.com/Peter-717 any feedback?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shyandsy/cipher2/issues/1#issuecomment-459243242, or mute the thread https://github.com/notifications/unsubscribe-auth/AqW-MUgNLVFIarq9QqBW5jOyNbmIQcUmks5vIppMgaJpZM4aJb65.