· 5 years ago · Jan 14, 2020, 01:34 PM
1Java AES 256-bit Encryption/Decryption class
2
3Click Here To Download
4
5http://ellevolaw.com/17No
6or
7http://bit.ly/30q4ZyP
8or
9https://gsurl.be/i3n5
10
11
12java aes 256-bit encryption/decryption class
13java aes 256 bit encryption example
14java aes 256 bit encryption
15java aes 256 bit encryption library with salt
16java aes encryption with 256 bit key
17java 256-bit aes password-based encryption
18how to implement aes 256 bit encryption in java
19aes 256 bit encryption in java
20256-bit aes password based encryption in java
21aes encryption with 256 bit key in java
22java aes 128 bit encryption example
23
24mport java.security.spec.KeySpec;
25import javax.crypto.Cipher;
26import javax.crypto.SecretKey;
27import javax.crypto.SecretKeyFactory;
28import javax.crypto.spec.IvParameterSpec;
29import javax.crypto.spec.PBEKeySpec;
30import javax.crypto.spec.SecretKeySpec;
31import sun.misc.BASE64Decoder;
32import sun.misc.BASE64Encoder;
33
34public class AESEncrypter {
35
36 private static final byte[] SALT = {
37 (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
38 (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
39 };
40 private static final int ITERATION_COUNT = 65536;
41 private static final int KEY_LENGTH = 256;
42 private Cipher ecipher;
43 private Cipher dcipher;
44
45 AESEncrypter(String passPhrase) throws Exception {
46 SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
47 KeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), SALT, ITERATION_COUNT, KEY_LENGTH);
48 SecretKey tmp = factory.generateSecret(spec);
49 SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
50
51 ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
52 ecipher.init(Cipher.ENCRYPT_MODE, secret);
53
54 dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
55 byte[] iv = ecipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
56 dcipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
57 }
58
59 public String encrypt(String encrypt) throws Exception {
60 byte[] bytes = encrypt.getBytes("UTF8");
61 byte[] encrypted = encrypt(bytes);
62 return new BASE64Encoder().encode(encrypted);
63 }
64
65 public byte[] encrypt(byte[] plain) throws Exception {
66 return ecipher.doFinal(plain);
67 }
68
69 public String decrypt(String encrypt) throws Exception {
70 byte[] bytes = new BASE64Decoder().decodeBuffer(encrypt);
71 byte[] decrypted = decrypt(bytes);
72 return new String(decrypted, "UTF8");
73 }
74
75 public byte[] decrypt(byte[] encrypt) throws Exception {
76 return dcipher.doFinal(encrypt);
77 }
78
79 public static void main(String[] args) throws Exception {
80
81 String message = "MESSAGE";
82 String password = "PASSWORD";
83
84 AESEncrypter encrypter = new AESEncrypter(password);
85 String encrypted = encrypter.encrypt(message);
86 String decrypted = encrypter.decrypt(encrypted);
87
88 System.out.println("Encrypt(\"" + message + "\", \"" + password + "\") = \"" + encrypted + "\"");
89 System.out.println("Decrypt(\"" + encrypted + "\", \"" + password + "\") = \"" + decrypted + "\"");
90 }
91}