What is AES?
AES is stands for Acronym of Advanced Encryption Standard which is an encrypting algorithm. In this algorithm you can use a 128-bit, 192-bit, or 256-bit long key for encrypting and decrypting data.
When is it helpful to use AES?
Anytime you want to hide information from your users.
Is AES secure?
AES has been adopted by the U.S. government and is now used worldwide.
AES is may not be secure for highly classified information but, however for the small to larger applications it is.
Here's a chart of possible combinations
=
What are some open-source alternatives?
AES Crypt: (Same but I will show you the differences)
- Platforms: Windows, OSX, Linux (Crypt4All Lite for Android is compatible)
- Encryption: AES_256
- Pros: Per file encryption, very easy to use
- Cons: individual file encryption only
AxCrypt
- Platform: Windows
- Encryption: AES_128 with HMAC-SHA1-128 data verification
- Pros: Per file encryption, right-click OS integration, can encrypt all files in a folder and multiple files at once, can use keyfile instead of a passphrase (more secure as greater entropy), more options than AES Crypt, stand-alone portable version available, very easy to use
- Cons: Windows only
DiskCryptor
- Platform: Windows
- Encryption: AES_256, Twofish and Serpent
- Pros: Full disk encryption (including OS disk), setup file only 1Mb, can use key file instead of password
- Cons: No per-file or per-folder encryption, no ‘hidden volumes’, no ‘hide drive’ option, unmounted drives still visible to system, Windows only
dm-Crypt/LUKS
- Platforms: Linux, DragonFly BSD, Android (Rooted only, using LUKS Manager)
- Encryption: Large library available, including blowfish, twofish and AES
- Pros: Very capable full disk encryption
- Cons: For experts only, impenetrable documentation
EncFS
- Platforms: Linux, Windows (using encfs4win), Android (using Cryptonite app). With a bit of effort it is possible to get EncFS to run in OSX *.
- Encryption: whatever libraries are available, usually Blowfish and AES. ‘Paranoid mode’ uses AES_256, , ‘filename block encoding with IV chaining per file, external IV chaining, MAC block headers’
- Pros: Easy to use, great for secure cloud storage, files encrypted individually
- Cons: Files in ‘personal’ folder are not encrypted, metadata (i.e. filenames and when a file is uploaded is modified in the cloud) is visible. Note that these are not really ‘cons’, but the logical consequences of EncFS’s strengths. Users should be aware of them however.
Secrecy
- Platforms: Android
- Encryption: AES_256
- Pros: Stealth mode to hide vaults, leaves no trace of any temporary files in the system
- Cons: Does not delete original files, can be somewhat slow, still very much in alpha development
I was looking around for various types of encryption in java and saw this which may be helpful to some. This has probably been released before if it has just let me know.
You can easily encrypt or decrypt any String, useful for passwords or anything you want to hide.
Example:
Code:
Origninal
MPGBXOaOKlulJUPcIJOr7w== NWTFcOwkohS7pEGJWCJOAA== N1yBiibb6VgkDEBBbrykAQ== tsVvZiKTjoGtVUrMmvvi2A==
Decrypted : YouTube, myYoutubePass#, 7/20/15, N/A
Origninal
x5jtavN4Zcre4p7/sSLChw== EwZePH7hTi1TU+QD7TYEZw== iF6xUrGTiIXxrsHoM2LLnw== tsVvZiKTjoGtVUrMmvvi2A==
Decrypted : My20Emails, abc123#, 07/24/2015, N/A
Origninal
VHVKdHzl4tV0ukwAZgGiTg== 3cqS9Zo+kBQ3dDiOGtiMHQ== iF6xUrGTiIXxrsHoM2LLnw== tsVvZiKTjoGtVUrMmvvi2A==
Decrypted : RS, whosanoob, 07/24/2015, N/A
Origninal
U7+XLGJq4ADy1lGz9NqTzg== ZJGkrLqbCBvM9m3NvqdR9g== iF6xUrGTiIXxrsHoM2LLnw== tsVvZiKTjoGtVUrMmvvi2A==
Decrypted : FaceBook, Password, 07/24/2015, N/A
Example usage in an application
Code:
private void loadEntries() {
try {
String file = "./data/data.dat";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = br.readLine();
while ((line = br.readLine()) != null) {
System.out.println("Origninal");
System.out.println(line);
String[] encryptedData = line.replaceAll("\t", " ").split(" ");
String encryptedName = encryptedData[0];
String encrpytedPass = encryptedData[1];
String encryptedDate = encryptedData[2];
String encryptedDate2 = encryptedData[3];
String encryptionKey = "ZmBe$oDUw34SfwXg";
EncryptionStandard advancedEncryptionStandard = new EncryptionStandard(
encryptionKey);
String decryptedUser = advancedEncryptionStandard
.decrypt(encryptedName);
String decryptedPass = advancedEncryptionStandard
.decrypt(encrpytedPass);
String decryptedDate = advancedEncryptionStandard
.decrypt(encryptedDate);
String decryptedDate2 = advancedEncryptionStandard
.decrypt(encryptedDate2);
System.out.println("Decrypted : " + decryptedUser + ", " + decryptedPass + ", "
+ decryptedDate + ", " + decryptedDate2);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
You'll have to use the apache commons library which can be found here.
Codec – Download Apache Commons Codec
Code:
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class EncryptionStandard
{
private String encryptionKey;
public EncryptionStandard(String encryptionKey)
{
this.encryptionKey = encryptionKey;
}
public String encrypt(String plainText) throws Exception
{
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
byte[] encryptedBytes = cipher.doFinal(plainText.getBytes());
return Base64.encodeBase64String(encryptedBytes);
}
public String decrypt(String encrypted) throws Exception
{
Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
byte[] plainBytes = cipher.doFinal(Base64.decodeBase64(encrypted));
return new String(plainBytes);
}
private Cipher getCipher(int cipherMode)
throws Exception
{
String encryptionAlgorithm = "AES";
SecretKeySpec keySpecification = new SecretKeySpec(
encryptionKey.getBytes("UTF-8"), encryptionAlgorithm);
Cipher cipher = Cipher.getInstance(encryptionAlgorithm);
cipher.init(cipherMode, keySpecification);
return cipher;
}
}
Usage
Code:
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) throws Exception {
String encryptionKey = "ZmBe$oDUw34SfwXg"; //Key must be 16 characters long (Can consist of letters, numeric values and special type characters)
String plainText = JOptionPane.showInputDialog("Enter something");
EncryptionStandard advancedEncryptionStandard = new EncryptionStandard(
encryptionKey);
String cipherText = advancedEncryptionStandard.encrypt(plainText);
String decryptedCipherText = advancedEncryptionStandard
.decrypt(cipherText);
System.out.println(plainText);
System.out.println(cipherText);
System.out.println(decryptedCipherText);
}
}