?? aescryptography.java
字號:
/**
* AES加密解密及相關方法
*/
package src;
import java.security.*;
import javax.crypto.*;
/**
* RSACryptography
* RSACryptography use the privated key to encrypt the plain text and decrypt
* the cipher text with the public key
*/
public class AESCryptography{
private Cipher cipher;
/**
* Default Constructure
* initialize the cipher
*/
public AESCryptography() {
try {
cipher = Cipher.getInstance("AES");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
}
}
/**
* @param byteInput input byte is the bytes want to be ciphered and deciphered it is up
* to the param crypto
* @param key used to cipher or decipher the byte
* @param crytpo if true, the function is used to cipher the bytes otherwise the bytes will
* be deciphered
* @return the bytes after ciphered or deciphered
*/
public byte[] encrypt_decrypt(byte[] byteInput, Key key, boolean crypto){
try {
if(crypto){
cipher.init(Cipher.ENCRYPT_MODE,key);
}else{
cipher.init(Cipher.DECRYPT_MODE,key);
}
byte[] cipherByte = cipher.doFinal(byteInput);
return cipherByte;
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -