我需要你帮我处理以下 java 文件
import java.lang.Math;
import java.util.Base64;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class HelloWorld
{
public static void main(String[] args)
{
OtherClass myObject = new OtherClass("pYQ4/pRt1g0EEdMuf8j2hg==", "nFgAIwY", "bkZnQUl3WVF1bXl2ZUpUYg==");
System.out.print(myObject);
}
}
public class OtherClass
{
private String message;
private boolean answer = false;
public String OtherClass(str,str2,str3)
{
AlgorithmParameterSpec ivParameterSpec = new IvParameterSpec(Base64.getDecoder().decode(str3.getBytes()));
Key secretKeySpec = new SecretKeySpec(str2.getBytes(), "AES");
Cipher instance = Cipher.getInstance("AES/CFB/NoPadding");
instance.init(2, secretKeySpec, ivParameterSpec);
return new String(instance.doFinal(Base64.getDecoder().decode(str.getBytes())));
}
public String toString()
{
return message;
}
}
我尝试在一些网站上在线测试 java 代码,并收到以下错误消息:检查类 header ...解析单个文件失败!
最佳答案
OtherClass myObject = new OtherClass("pYQ4/pRt1g0EEdMuf8j2hg==", "nFgAIwY", "bkZnQUl3WVF1bXl2ZUpUYg==");
您调用了构造函数。首先您需要了解构造函数和方法。
编辑
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Base64;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class SampleCode {
public static void main(String[] args) throws Exception, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, BadPaddingException, Exception
{
SampleCode sampleCode =new SampleCode();
OtherClass myObject = sampleCode.new OtherClass();
System.out.print(myObject.OtherClassMethod("pYQ4/pRt1g0EEdMuf8j2hg==", "nFgAIwY", "bkZnQUl3WVF1bXl2ZUpUYg=="));
}
public class OtherClass {
private String message;
private boolean answer = false;
public String OtherClassMethod(String str, String str2, String str3) throws NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, Exception,
BadPaddingException {
AlgorithmParameterSpec ivParameterSpec = new IvParameterSpec(Base64.getDecoder().decode(str3.getBytes()));
Key secretKeySpec = new SecretKeySpec(str2.getBytes("UTF-16"), "AES");
Cipher instance = Cipher.getInstance("AES/CFB/NoPadding");
instance.init(2, secretKeySpec, ivParameterSpec);
return new String(instance.doFinal(Base64.getDecoder().decode(str.getBytes())));
}
@Override
public String toString() {
return message;
}
}
}
试试这个
关于java - 如何修复java编译时的一些错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56988834/