📄 simpleexample.java
字号:
import java.security.*;import javax.crypto.*;public class SimpleExample{ public static void main(String[] args) throws Exception{ if (args.length!=1){ System.out.println("Usage: java SimpleExample text"); System.exit(1);}String text=args[0];System.out.println("Generate a DESede key….");KeyGenerator keyGenerator= KeyGenerator.getInstance("DESede");keyGenerator.init(168);Key key= keyGenerator.generateKey();System.out.println("done generating the key.");//create a cipher using that key to initialize itCipher cipher= Cipher.getInstance("Desede/ECB/PKCS5Padding");cipher.init(Cipher.ENCRYPT_MODE, key);byte[] plaintext =text.getBytes("UTF8");//print out the bytes of the plaintextSystem.out.println("\n plaintext:");for (int i=0;i<plaintext.length;i++) { System.out.print(plaintext[i]+" ");}//perform the actual encryption byte[] ciphertext=cipher.doFinal(plaintext);//print out the ciphertextSystem.out.println("\n\nCiphertext: ");for (int i=0;i<plaintext.length;i++) { System.out.print(plaintext[i]+" ");}//re-initialize the cipher to decrypt modecipher.init(Cipher.DECRYPT_MODE, key);//perform the decryptionbyte[] decryptedText=cipher.doFinal(ciphertext);String output =new String(decryptedText ,"UTF8");System.out.println("\n\nDecrypted text: "+output);}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -