Note that there are some explanatory texts on larger screens.

plurals
  1. POEncryption class working in java but not in android, why? What else can i do?
    primarykey
    data
    text
    <p>I did a simple encrypt/decrypt string class in java and tested it. It workes fine, now im trying to use it in an android device to encrypt a string, send it to my server and there decrypt it. All using the same custom class. Why is this not working? Is it simply not supported? what else can i do to easily encrypt/decrypt a string for this purpose? Base64 is not accepted:)</p> <pre><code>package crypto; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class Crypto { public static byte[] encrypt(String message) throws Exception { String symmetricKey = "25Ae1f1711%z1 )1"; SecretKeySpec aesKey = new SecretKeySpec(symmetricKey.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); cipher.init(Cipher.ENCRYPT_MODE, key); return cipher.doFinal(message.getBytes()); } public static String decrypt(byte[] encryptedMessage) throws Exception { String symmetricKey = "25Ae1f1711%z1 )1"; SecretKeySpec aesKey = new SecretKeySpec(symmetricKey.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); cipher.init(Cipher.DECRYPT_MODE, key); return new String(cipher.doFinal(encryptedMessage)); } } </code></pre> <p>In logcat i can see the following exception pop up: java.security.NoSuchProviderException: Provider not avalible: SunJCE</p> <p>I deleted the specified provider "SunJCE" from the line.</p> <pre><code>Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); </code></pre> <p>i found the solution to this over <a href="https://stackoverflow.com/questions/16335223/nosuchproviderexception-when-encrypting-string-with-3des">here</a></p> <p>now i get this error at the serverside instead:</p> <pre><code>javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750) at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676) at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:317) at javax.crypto.Cipher.doFinal(Cipher.java:1813) at crypto.Crypto.decrypt(Crypto.java:20) at io.network.UDPServer.run(UDPServer.java:37 </code></pre> <p>tried with BC but i still have the same error</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload