java - 如何修复java编译时的一些错误

标签 java

我需要你帮我处理以下 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/

相关文章:

java - 嵌入式 Firebird 数据库和 Hibernate

java - 如何在另一个类中调用一个类的 main() 方法?

java - 未针对上限类型参数检查下限通配符

java - 我应该如何使用 servlet 和 Ajax?

java - 项目 Maven 依赖项中重复了 log4j.xml

java - Android:将数据从surfaceView传递到其父 Activity

java - 强制覆盖 DynamoDB 表名称

java - AS400 角色扮演游戏模拟器

Java netbeans - 如果 jtextfield 值为空,如何将 jtextfield 值分配为零

java - 如何将参数传递给 HttpServer 的实现?