1 public class text {
2 static final byte[] bytes_a = new byte[]{66, 108, 111, 119, 102, 105, 115, 104};
3 static final byte[] bytes_key = new byte[]{104,101,108,108,111,50,48,49,55};
4 static final byte[] bytes_content = new byte[]{103,111,111,100,32,106,111,98,32,77,121,32,102,114,105,101,110,100};
5 public static void main(String[] args) {
6
7
8 SecretKeySpec se_key = new SecretKeySpec(bytes_key,new String(bytes_a));
9 byte[] target = encrypt(se_key,bytes_content);
10 System.out.println(new String(target));
11 byte[] bytes = decrypt(se_key,target);
12 System.out.println(new String(bytes));
13 }
14
15 public static byte[] encrypt(Key key, byte[] text){
16 try {
17 Cipher cipher = Cipher.getInstance(new String(bytes_a));
18 cipher.init(Cipher.ENCRYPT_MODE,key);
19 return cipher.doFinal(text);
20 } catch (NoSuchAlgorithmException e) {
21 e.printStackTrace();
22 } catch (NoSuchPaddingException e) {
23 e.printStackTrace();
24 } catch (InvalidKeyException e) {
25 e.printStackTrace();
26 } catch (BadPaddingException e) {
27 e.printStackTrace();
28 } catch (IllegalBlockSizeException e) {
29 e.printStackTrace();
30 }
31 return null;
32 }
33 public static byte[] decrypt(Key key, byte[] text){
34 try {
35 Cipher cipher = Cipher.getInstance(new String(bytes_a));
36 cipher.init(Cipher.DECRYPT_MODE,key);
37 return cipher.doFinal(text);
38 } catch (NoSuchAlgorithmException e) {
39 e.printStackTrace();
40 } catch (NoSuchPaddingException e) {
41 e.printStackTrace();
42 } catch (InvalidKeyException e) {
43 e.printStackTrace();
44 } catch (BadPaddingException e) {
45 e.printStackTrace();
46 } catch (IllegalBlockSizeException e) {
47 e.printStackTrace();
48 }
49 return null;
50 }
51 }
public class text {
static final byte[] bytes_a = new byte[]{66, 108, 111, 119, 102, 105, 115, 104};
static final byte[] bytes_key = new byte[]{104,101,108,108,111,50,48,49,55};
static final byte[] bytes_content = new byte[]{103,111,111,100,32,106,111,98,32,77,121,32,102,114,105,101,110,100};
public static void main(String[] args) {
SecretKeySpec se_key = new SecretKeySpec(bytes_key,new String(bytes_a));
byte[] target = encrypt(se_key,bytes_content);
System.out.println(new String(target));
byte[] bytes = decrypt(se_key,target);
System.out.println(new String(bytes));
}
public static byte[] encrypt(Key key, byte[] text){
try {
Cipher cipher = Cipher.getInstance(new String(bytes_a));
cipher.init(Cipher.ENCRYPT_MODE,key);
return cipher.doFinal(text);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
return null;
}
public static byte[] decrypt(Key key, byte[] text){
try {
Cipher cipher = Cipher.getInstance(new String(bytes_a));
cipher.init(Cipher.DECRYPT_MODE,key);
return cipher.doFinal(text);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
return null;
}
}