pri_encrypter.java
来自「非常有用的加密解密程序」· Java 代码 · 共 61 行
JAVA
61 行
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 + =
减小字号Ctrl + -
显示快捷键?