Encryption And Decryption of Json Input String with Key

137 views
Skip to first unread message

vamsi krishna

unread,
Jun 15, 2021, 2:10:42 AM6/15/21
to Flutter Development (flutter-dev)
This is my input in Android : 

{"Idno":"DK8788","Pwd":"d7877578788k","Action":"Profile"}


Encryption : s\/cBy3hAQ3bI5Ek5L+QKrK3Cy5HF8+iSsHHOV1YEcAEJLk4dQ4oYkTS1zoY\/1ZFvV7YaJzAhkZ4Q\ngkI51mJCqQ==\n


But in my code i am getting  

nr0yG3cg/+98i2JCRtj+vdKRJ71f+ItOYjYMqj07oohNATc43yOoHlJ68n8oxe6gSy/eq8z8lydkm+4cjwoNHA==


var plainText = '{"Idno":"DK8788","Pwd":"d7877578788k","Action":"Profile"}';
final key = aes.Key.fromUtf8('Al@ex%oZawyerXYx');

final iv = aes.IV.fromLength(16);

final encrypter = Encrypter(AES(key, mode: AESMode.cbc,padding: 'PKCS7'));

final encrypted = encrypter.encrypt(plainText, iv: iv);

final decrypted = encrypter.decrypt(encrypted, iv: iv);

print("Decrypt : $decrypted");

print("Encrypt : $encrypted".toString());
print(encrypted.base64);

Please Help Me I am trying last one week

vamsi krishna

unread,
Jun 19, 2021, 6:14:11 AM6/19/21
to Suzuki Tomohiro, Flutter Development (flutter-dev)

Jack Sun

unread,
Jun 19, 2021, 10:15:26 AM6/19/21
to vamsi krishna, Suzuki Tomohiro, Flutter Development (flutter-dev)
Looks your function is correct. 

If your  '$decrypted' is correct with the original jsonString (plainText), your function does the correct job.

For difference with your "Android output", may due to param and/key selection.  


Jack

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/CAAWJ9htZxjx6FObOOpUuvZjcHoYPn-7jcRNQ17X%3D%3D3%3D3UQhung%40mail.gmail.com.

vamsi krishna

unread,
Jun 19, 2021, 11:12:32 AM6/19/21
to Jack Sun, Suzuki Tomohiro, Flutter Development (flutter-dev)
Thank you for the clarification. but Params and key are same in both and flutter

Jack Sun

unread,
Jun 19, 2021, 6:10:30 PM6/19/21
to vamsi krishna, Suzuki Tomohiro, Flutter Development (flutter-dev)
Hi Vamsi,

I tried your codes in iOS simulator (iPadOS 14.5) and got the same results as you got, different from your Android.
May I ask what "Input in Android" means?   The same code is deployed on the Android simulator or other apps/packages?

Any other suggestions?

Jack
Reply all
Reply to author
Forward
0 new messages