2013-12-09 41 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