I am working on a program that should store binary information encrypted at rest. Unfortunately, I cannot find a resource that explains which encryption schemes are best suited for different applications.
Since encryption is complex, and I'm not an expert, I decided to use a library called Jasypt , which wraps the Java construct in encryption functions. To find out which algorithms are available to me, I wrote several unit tests.
The first test calls the Jasypt AlgorithmRegistry.getAllPBEAlgorithms()
function and lists all available encryption algorithms:
PBEWITHHMACSHA1ANDAES_128 PBEWITHHMACSHA1ANDAES_256 PBEWITHHMACSHA224ANDAES_128 PBEWITHHMACSHA224ANDAES_256 PBEWITHHMACSHA256ANDAES_128 PBEWITHHMACSHA256ANDAES_256 PBEWITHHMACSHA384ANDAES_128 PBEWITHHMACSHA384ANDAES_256 PBEWITHHMACSHA512ANDAES_128 PBEWITHHMACSHA512ANDAES_256 PBEWITHMD5ANDDES PBEWITHMD5ANDTRIPLEDES PBEWITHSHA1ANDDESEDE PBEWITHSHA1ANDRC2_128 PBEWITHSHA1ANDRC2_40 PBEWITHSHA1ANDRC4_128 PBEWITHSHA1ANDRC4_40
At run time, Jasypt will throw an EncryptionOperationNotPossibleException
if you try to use an algorithm that for some reason is not supported or does not violate Java encryption rules. Interestingly, if I try to use each of the available algorithms for encryption, and then decrypt some arbitrary data and print only those that do not throw this exception, I get this short list:
PBEWITHMD5ANDDES PBEWITHSHA1ANDDESEDE PBEWITHSHA1ANDRC2_128 PBEWITHSHA1ANDRC2_40 PBEWITHSHA1ANDRC4_128 PBEWITHSHA1ANDRC4_40
The list of available algorithms can be expanded by pulling the BouncyCastle JCE and registering it by executing Security.addProvider(new BouncyCastleProvider())
. If I repeat the previous test after this, I get a much larger list of algorithms to choose from:
PBEWITHMD2ANDDES PBEWITHMD5AND128BITAES-CBC-OPENSSL PBEWITHMD5AND192BITAES-CBC-OPENSSL PBEWITHMD5AND256BITAES-CBC-OPENSSL PBEWITHMD5ANDDES PBEWITHMD5ANDRC2 PBEWITHSHA1ANDDES PBEWITHSHA1ANDDESEDE PBEWITHSHA1ANDRC2 PBEWITHSHA1ANDRC2_128 PBEWITHSHA1ANDRC2_40 PBEWITHSHA1ANDRC4_128 PBEWITHSHA1ANDRC4_40 PBEWITHSHA256AND128BITAES-CBC-BC PBEWITHSHA256AND192BITAES-CBC-BC PBEWITHSHA256AND256BITAES-CBC-BC PBEWITHSHAAND128BITAES-CBC-BC PBEWITHSHAAND128BITRC2-CBC PBEWITHSHAAND128BITRC4 PBEWITHSHAAND192BITAES-CBC-BC PBEWITHSHAAND2-KEYTRIPLEDES-CBC PBEWITHSHAAND256BITAES-CBC-BC PBEWITHSHAAND3-KEYTRIPLEDES-CBC PBEWITHSHAAND40BITRC2-CBC PBEWITHSHAAND40BITRC4 PBEWITHSHAANDIDEA-CBC PBEWITHSHAANDTWOFISH-CBC
Unfortunately, now I do not know which of these algorithms is most suitable for my application. I have a suspicion that AES is the right way, and it looks like PBEWITHSHA256AND256BITAES-CBC-BC
is the AES implementation with the longest key length, but I don’t know where to go to confirm this suspicion.
Which of these schemes will provide the highest levels of security and which have obvious security concerns?
EDIT:. I want to be able to distribute my code without requiring the end user to install unlimited cryptography files, as this will almost certainly be beyond the capabilities of less experienced users. What I really want is the strongest encryption I can get without using files of unlimited strength.