Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple one line, native encrypt/decrypt method in Java

Is there a dead-simple native method in Java to encrypt/decrypt a string with a key? I don't really care what type of encryption (AES, DES, etc..), I just care that it's bound by with a key and not easily breakable.

Ideally, I would like it to be a one line solution like so:

String encryptedString = NativeEncryptionClass.encrypt("this is the data", "key123");

Thanks

like image 500
Tyler Murry Avatar asked Nov 17 '11 23:11

Tyler Murry


3 Answers

Not sure you can do it in a [legiable] one-liner, but you can achieve simple symmetrical encryption relatively easily - take a look at the following example:

PrivateExample using DES

I've used the Bouncy Castle library to good effect in the past.

like image 64
Duncan Avatar answered Oct 05 '22 11:10

Duncan


If by native you mean, not depending on platform specific libraries, maybe jasypt might be interesting for you.

like image 23
martin Avatar answered Oct 05 '22 11:10

martin


May be you should try using simple XOR encryption

like image 34
user93 Avatar answered Oct 05 '22 12:10

user93