3
後爲什麼會出現在該行語法錯誤(如下所示)語法錯誤「;」,{預期此令牌
package org.temp2.cod1;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
public class Code1 {
byte[] plaintext = new byte[32]; // <<<<<<<<<<<<<<<<<<<<<<<<<< syntax error
for (int i = 0; i < 32; i++) {
plaintext[i] = (byte) (i % 16);
}
byte[] key = new byte[16];
SecureRandom r = new SecureRandom();
r.nextBytes(key);
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k = new SecretKeySpec(key, "AES");
c.init(Cipher.ENCRYPT_MODE, k);
byte[] encryptedData = c.doFinal(plaintext);
}
}
eclipse建議添加 public static void main(String [] args)throws NoSuchAlgorithmException,NoSuchPaddingException,InvalidKeyException,IllegalBlockSizeException,BadPaddingException是否可以? – silverkid 2009-11-18 11:24:36
是的 - 雖然你可以省略拋出子句,如果你沒有拋出任何這些例外。 – 2009-11-18 11:31:43