3

So, how do I do it? Can't find any example anywhere that successfully uses RC4. Also, doing cipher = Cipher.getInstance("RC4"); returns a NoSuchAlgorithm exception

skaffman
  • 398,947
  • 96
  • 818
  • 769
josephus
  • 8,284
  • 1
  • 37
  • 57
  • Why do you want to use RC4? It's very easy to misuse – CodesInChaos Feb 10 '12 at 09:52
  • I want to encrypt/decrypt Video files, and AES won't cut it because it's too slow. Don't worry about me misusing RC4, that could be taken care of after I figure out how to use it. :) – josephus Feb 10 '12 at 10:05
  • 2
    AES should be able to decrypt video files far beyond real time. You probably want random access, so I'd recommend using AES in CTR mode. – CodesInChaos Feb 10 '12 at 10:40
  • If you absolutely must have RC4 then just implement it yourself. It's only a few lines. On my system, using `openssl speed`, rc4 is about 2.5 times faster than aes-128. – President James K. Polk Feb 10 '12 at 12:43

1 Answers1

3

If you list the available Ciphers:

    Provider[] providers = Security.getProviders();
    for (Provider provider : providers) {
        for (Object entry : provider.keySet()) {
            String name = String.valueOf(entry);
            if (name.startsWith("Cipher")) {
                Log.d("Cipher", "Supports: " + name.substring(7));
            }
        }
    }

There's a few RC4 variants - such as PBEWITHSHAAND128BITRC4 (PKCS#5). Which one do you need?

Jens
  • 16,853
  • 4
  • 55
  • 52
  • This list is different for each type of device (or at least Android version). I'm using 2.2, and grepping through my list gives no rc4 variant. From what device is that list from? – josephus Feb 10 '12 at 10:02
  • This is from ICS. If I flash the device back to 2.3.4 you'd still find PBEWITHSHAAND128BITRC4 for instance. – Jens Feb 10 '12 at 10:05
  • As said, mine is 2.2. Also, another goal is to allow the application to run on lower-end phones - 2.2 and below. – josephus Feb 10 '12 at 10:08
  • In that case, refactor (so it doesn't conflict with whatever's in your device) & include the "latest and greatest" bouncy-castle jar into your project and go from there. – Jens Feb 10 '12 at 10:09
  • 1
    The latest and greatest bouncycastle for android is spongycastle. – President James K. Polk Feb 10 '12 at 12:38
  • Ooh, nice. It's always nice when someone fixed the annoying bits already. https://github.com/rtyley/spongycastle – Jens Feb 10 '12 at 12:50