I have a string as follows:
Unless this is a homework assignment I'd suggest you to use Base64 encoding: new sun.misc.BASE64Encoder().encode(string.getBytes())
.
This does not encrypt string but makes it unreadable.
If you really want to encrypt the string use java cryptography API, e.g:
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, password);
String encrypedStr = base64encoder.encode(cipher.doFinal(cleartext));
Now encryptedString
is encrypted and stored in base64 format.
You can easily find how to decrypt the string back. Good luck.