0

I need to do encryption and Decryption in android,

Now I use 'AES' Algorithm Encryption,I got Some Encryption Values Like'�*��1FO��' but I need Output like this '38533F4B3F3852203F443F3F283F3F'

Any one have idea..

My Code for Encryption

            IvParameterSpec _IVParamSpec = new IvParameterSpec(IV);
        SecretKeySpec sks = new SecretKeySpec(KEY, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, sks,_IVParamSpec);
        /*byte[] bt = new byte[256] ;
               bt = hexStringToByteArray(strToDecrypt);*/
        //final String decryptedString1 = new String(cipher.doFinal(bt));
                //final String decryptedString = new String(cipher.doFinal(strToDecrypt.getBytes("UTF-16LE")));
                final String decryptedString2 = new String(cipher.doFinal(Base64.decode(strToDecrypt, Base64.NO_WRAP)));
                String StrHex = toHex(decryptedString);
        final String decryptedString1 = new String(cipher.doFinal(strToDecrypt.getBytes()));
saravanan
  • 388
  • 2
  • 18
  • So you are asking how to convert a byte array to a hexadecimal string in Java? http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java – Alex K. Apr 17 '15 at 10:23
  • 38533F4B3F3852203F443F3F283F3F is Hex String, it's not encreypted. what's your original data? – Amir Apr 17 '15 at 10:24
  • @Amir For Example if enter 'userid' means, i need output like this '40d44d0' with encryption AES – saravanan Apr 17 '15 at 10:26
  • @saravanan '40d44d0' is not a hex encoding of 'userid' and is too short to be a hex encoding of the encrypted 'userid'. What are you talking about? Please describe in detail what you want to achieve. – Artjom B. Apr 17 '15 at 10:58
  • 1
    If you want to convert a byte array to something that can be treated as text, then Base64 takes up less space than hex (=Base16). – rossum Apr 17 '15 at 15:13
  • @ArtjomB. could you please help me with my question http://stackoverflow.com/questions/43224137/how-to-decrypt-the-data-with-a-key?noredirect=1#comment73521358_43224137 – Sirop4ik Apr 05 '17 at 08:52

1 Answers1

0

use this package:
http://commons.apache.org/proper/commons-codec/
it supports converting Hex Strings and also provides various encryption except AES (AFAIK)

Amir
  • 1,250
  • 18
  • 22
  • Please try and format your sentences, this is not YouTube, we try and avoid YouTube type of language because it dumbs down the site. – Maarten Bodewes Apr 18 '15 at 13:43