1

My file encryption is very slow! 2 minutes for 70 Mb. I use this library and class for Encrypting files. It works but it's very slow. E.g. for a file .mp4 (70Mb) the encryption takes 2 minutes.

I searched a lot in this site and internet but couldn't find a fast way. My encrypt class is JealousSky :

JealousSky.class

My code for Encryption is this :

try {
        jealousSky.initialize(
                "longestPasswordEverCreatedInAllTheUniverseOrMore",
                "FFD7BADF2FBB1999");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    try {
        InputStream is = new FileInputStream(listFiles[position]);
        jealousSky.encryptToFile(is,listFiles[position].getParent()+"/"+EncName);
        givenFile.delete();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    }

Edit :

Solution

in JealousSky.class and encrypt method must to change (getEncryptInputStream) to (getDecryptFromCipherInputStream)

finaly 2min decreased to 12s

sbr
  • 81
  • 8
  • You should [edit](https://stackoverflow.com/posts/55327793/edit) your post to list out what hardware/OS version you are testing on. Also state if you tried on different devices. – Morrison Chang Mar 24 '19 at 20:20
  • what encryption algorithm are you using? what key length? – Hichem BOUSSETTA Mar 24 '19 at 21:41
  • Use buffered streams for input and output. – user207421 Mar 24 '19 at 21:53
  • 1
    You need to get better at choosing libraries. JealousSky says it's "an efficient library", but it also says it's "still in progress", and it hasn't been updated for three years. It has only two contributors, 29 commits, no branches or pull requests, and hardly even any open issues. In short, a dead library, used by almost no one. Not a good choice for encryption. – DavidS Mar 25 '19 at 23:31
  • @DavidS Do you have a better library for encrypting files? – sbr Mar 25 '19 at 23:50
  • 1
    JCE is such a library and it is already part of the JDK. – user207421 Mar 25 '19 at 23:58

1 Answers1

0

You need to specify what kind of encryption you want, there will be different speed for different specifications.

Regardless, I suggest you to use other encryption libraries that are better written and maintained, I have no experience with the library you named, but you can consider the native Java security components like Java Cryptography Architecture, if that can't do the job for you, then research further on other third-party libraries.

Jack
  • 5,354
  • 2
  • 29
  • 54
  • that Library use AES bytes[16] – sbr Mar 24 '19 at 20:04
  • 2
    @fazel Normally the encryption itself should not take so long. As well I see that JealousSky library is doing terrible job with memory management (getEncryptInputStream), seems it's a pretty lousy implementation. Just use pure Java crypto (if you can do that properly). – gusto2 Mar 25 '19 at 15:55
  • that's exactly my point, thanks for clarifying, you put it better than I did. – Jack Mar 25 '19 at 22:08
  • @gusto2 ♥♥♥♥♥ yesssss ,, i changed the (getEncryptInputStream) and use from (getDecryptFromCipherInputStream) for both (encrypt / decrypt) ,,, finaly 2min decreased to 12s – sbr Mar 25 '19 at 23:06