privateexample.java

来自「非常有用的加密解密程序」· Java 代码 · 共 35 行

JAVA
35
字号
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 + =
减小字号Ctrl + -
显示快捷键?