AES encryption between Android and Arduino -


Hi I am working on the communication between Android and arduino through a Bluetooth module. And I must offer some protection I AES'm trying to put encryption but I have problems with my my Ardino code I can encrypt / decrypt using Diisielbi and sample code Davy Landman

  Enter the code here  

uint8_t key [] = {'A', 'B', 'C', 'D', 'E', 'F', 'J ',' A ',' i ',' j ',' kashmir ',' l ',' m ',' n ',' o ',' p '}; Four data [] = "0123456789012345"; // 16 characters == 16 bytes aes128_enc_single (key, data); Serial.print ("encrypted:"); Serial.println (data); Aes128_dec_single (key, data); Serial.print ("decrypted:"); Serial.println (data);

and Android I can square up on the stack overflow with Aisaclpr encrypted using an example / decrypt do:

  code to enter the com. Example.bluetooth2; Import java.security.SecureRandom; Import javax.crypto.Cipher; Import javax.crypto.KeyGenerator; Import javax.crypto.SecretKey; Import javax.crypto.spec.SecretKeySpec; Public class AESHlp {Public String String Encrypted (String Beed, String Claretext) Exceptions {Bite [] Raw Kay = MilkingCoco (Beed Butt Bates ()); Byte [] Results = Encrypt (rawKey, cleartext.getBytes ()); Return (results); } Public static string decrypt (string bead, string encrypted) throws an exception {byte [] kachikeyya = (seed button) ()); Byte [] Enque = Tubet (encrypted); Byte [] results = decrypt (raw, ac); New string return (results); } Private static byte [] getRawKey (byte [] seed) throws an exception {KeyGenerator kgen = KeyGenerator.getInstance ("AES"); SecureRendam SR = SecureRendam Get Instance ("SHA1 PRNGN", "Crypto"); Sr.setSeed (seeds); Kiloanite (128, SR); // 192 and 256 bits may not be available SecretKey skey = kgen.generateKey (); Byte [raw] = skey.getEncoded (); Return raw; } Private static encrypted byte [] (byte [] throws raw, clear byte []) Expansion (Sikretke Speak ski Speak = new Sikretkespiisi (raw, "AES"); Saifr Saifr = cipher. Gate instance ( "AES"); Cypher. it (Cypher. Ansiarwaipi_modii, Skispiisi); byte [] encrypted = cipher Kdofnl (clear); encrypted return;} private static byte [] decrypt (byte [] cast, byte [] encrypted) throws an exception [{Guptki Speak skeySpec = new Sikretkespiisi (raw, "AES"); Saifr Saifr = cipher. Gate instance ( "AES"); Cipher. It (Cypher. Diisiarapitimmiidii, Skispiisi); byte] decrypted = Saifrkdofinl (encrypted) ; Back Decrypted;} Public Static String Tohex (String TSTT) {Hex for return (textual butts);} Hex (string hex) from public static string {new string (to Return byte (hex)); public static byte [] toByte (string hexstrings) {int len ​​= hexString.length () / 2; byte [] results = new byte [lane]; for (int i = 0 ; I & lt; len; i ++) Result [i] = integer.valof (hexstring. Bustring (2 * i, 2 * i + 2), 16) .BitVela (); Return result; } Public Static String Tohex (Byte [] Buff) {if (buf == null) "" Return; String buffer result = new string buffer (2 * buf.length); For (int i = 0; i  4) & amp; 0x0 F) Annex (Hex Chatch (B & F 0x0 F)); }} And with the main action code: Enter the code here publicly string beed value = "ABCDGGILMNOP"; Public static string message = "Benfica"; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); {String Encrypted Data = AESHLper.Encrypt (Seed Value, Message); Logs. V ("encrypted decrypt", "encoded string", + encrypted data); String decrypted data = AESHLper.d Decrypt (Beed Well, Encrypted Data); Logs. V ("decrypt", "decoded string", + decrypted data); } Hold (exception e) {e.printStackTrace (); }}}  

But the problem is that I can not decrypt the data encrypted from Android and vice versa.

Can anyone help me?

I am inexperienced with this problem.

Mr. Davey Landman from AESELB asks me to match CBC mode. He says that using the code CBC mode, and Android I try to keep it with the next two lines

AES / CBC / No Peeding or AES / CBC / PKCS 5 padding

Please, if anybody knows how to be correct, please save my life :)

Best Relationship


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -