First: if at all possible, do not do it yourself. Encryption is very (very!) Easy to mess up in ways that make the results unsafe. If at all possible, use an external component or library to do as much of the encryption work as possible.
Secondly, if you do it yourself, as of now, do not use DES. DES is no longer a strong enough cipher. Triple-DES is fine, but what you really want to use is AES. He believed that during its development reliable modern processors were taken into account, you get a choice of key lengths to balance security from performance, and modern processors have hardware acceleration for AES (AES-NI). (I donโt know if Java uses this, but if it is not, it can certainly start in the future, while the chances for Triple-DES are zero.)
Third, you read and write bytes at a time. Despite the fact that in any case, encryption will be intensively loaded into the CPU, doing it the way you are now will be slower than necessary. Reading and writing with byte[] 4 kB or so should have much better performance.
source share