⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aescryptography.java

📁 一个简单的实现Kerberos验证的程序
💻 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 + -