OSX中的macos Java编译问题
代码:
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class crypto {
public static void main(String [] args) {
String s = args[0];
String s1 = args[1];
String ivkey = "thisisasecretword1";
byte[] ivraw = ivkey.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(ivraw, "AES");
byte[] iv = { 't','h','i','s','a','s','e','c','r','e','t','w','o','r','d','1' };
IvParameterSpec ivspec = new IvParameterSpec(iv);
if (s.equalsIgnoreCase("ENCRYPT")) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
byte[] encrypted = cipher.doFinal(s1.getBytes());
System.out.println("encrypt: " + new String(Base64.encodeBase64(encrypted)));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec);
byte[] encrypted = cipher.doFinal(Base64.decodeBase64(s1));
System.out.println("decrypt: " + new String(encrypted));
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
我试图编译这篇文章只是为了测试我们正在考虑使用的新加密方法。这是第一次迭代,但将在以后尽职尽责地保护它,以实现随机密钥。无论如何,当我试图编译这个时,我在osx中将我的classpath
设置为commons-coded-1.9.jar
所在的位置。我运行了javac crypto.java
,没有错误。我运行java crypto "ENCRYPT" "TEST"
并得到一条NoClassDefFoundError: crypto
消息。我一直在搞砸这件事,但看不出是哪里出的错。希望有一双新的眼睛能照亮它
共 (0) 个答案