2013-12-09 60 views
0

我試圖設置AES加密的應用程序和Eclipse拋出以下錯誤:AES加密初始化錯誤

"Multiple markers at this line 
    - Syntax error on tokens, ConstructorHeaderName expected instead 
    - Syntax error on token "(", < expected 
    - Syntax error on tokens, ConstructorHeaderName expected instead" 
上線

enccipher.init(Cipher.ENCRYPT_MODE, secretkey);

deccipher.init(Cipher.DECRYPT_MODE, secretkey, new IvParameterSpec(iv));

這是我的代碼:

private final byte[] salt = new SecureRandom().generateSeed(8); 
SecretKeyFactory fact = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); 
KeySpec spec = new PBEKeySpec(null, salt, 65536, 256); 
SecretKey tempsecret = fact.generateSecret(spec); 
private SecretKey secret = new SecretKeySpec(tempsecret.getEncoded(), "AES"); 

private Cipher enccipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
enccipher.init(Cipher.ENCRYPT_MODE, secret); 
private final byte[] iv = enccipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV(); 

private Cipher deccipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
deccipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv)); 

protected byte[] doEncrypt(String pass){ 
    return enccipher.doFinal(pass.getBytes()); 
} 
protected String doDecrypt(byte[] ciphertext) { 
    return new String (deccipher.doFinal(ciphertext), "UTF8"); 
} 
+0

這應該被保護字節[] doEncrypt(字符串通){ 返回enccipher.doFinal(pass.getBytes()); } – Honanin

回答

4

發佈您的代碼 - 但我的猜測是,你剛進入文本類主體(在那裏說:does not go not here),而不是內部的方法(在那裏說:code goes here)。

public class XYZ { 

    // variable and method declarations go here 
    // code does not go here 

    public XYZ() { 
    // code goes here 
    } 
} 
+0

你說得對,我認爲它是在一個方法中,但我錯了。謝謝您的回答! – Honanin