?? privateexample.java
字號:
package ss.logic;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import java.security.Key;
public class PrivateExample{
public static void main(String[] args) throws Exception{
String plainTextStr = "ABCEETR$%#?><E#2213";
byte[] plainText = plainTextStr.getBytes("UTF8");
System.out.println(plainTextStr);
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(128);
Key key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] cipherText = cipher.doFinal(plainText);
//String cipherTextStr = new String(cipherText, "UTF8");
//System.out.println(cipherTextStr);
String str = new String(cipherText);
cipherText = str.getBytes();
cipher.init(Cipher.DECRYPT_MODE,key);
byte[] newPlainText = cipher.doFinal(cipherText);
String newPlainTextStr = new String(newPlainText, "UTF8");
System.out.println(newPlainTextStr);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -