📄 pri_encrypter.java
字号:
package ss.logic;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
public class Pri_Encrypter {
public static void main(String[] args) throws Exception{
a.encrypt("ADDFDFDF");
a.decrypt("sdsd");
}
static Pri_Encrypter a = new Pri_Encrypter();
public void encrypt(String plainTextString) throws Exception{
plainTextStr = plainTextString;
plainText = plainTextStr.getBytes("UTF8");
System.out.println(plainTextStr);
keyGen = KeyGenerator.getInstance("AES");
keyGen.init(128);
key = keyGen.generateKey();
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,key);
realCipherText = cipher.doFinal(plainText);
System.out.println(new String(realCipherText, "UTF8"));
}
public void decrypt(String cipherString) throws Exception{
cipherText = cipherString.getBytes();
cipher.init(Cipher.DECRYPT_MODE,key);
newPlainText = cipher.doFinal(cipherText);
newPlainTextStr = new String(newPlainText, "UTF8");
System.out.println(newPlainTextStr);
}
private String plainTextStr;
private byte[] plainText;
private KeyGenerator keyGen;
private Key key;
private Cipher cipher;
private byte[] cipherText;
private byte[] realCipherText;
private byte[] newPlainText;
private String newPlainTextStr;
public String getRealCipherText(){
return new String(realCipherText);
}
public String getNewPlainTextStr() {
return newPlainTextStr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -