【发布时间】:2017-06-09 15:04:11
【问题描述】:
我正在尝试使用第三方 Java 代码使用 AES/ECB 加密数据。提供数据和密钥。代码如下:-
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class encryptData {
public static void main(String[] args) {
String data="amount=10&expiryDate=20150101 151515&orderRefNum=11001&postBackURL=http://localhost:9081/local/status.php&storeId=28";
String key="89OUITUPRL3I8H3G";
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
}
}
我正在https://www.compilejava.net/上试用
这是我得到的错误:-
/tmp/java_Ramvov/encryptData.java:16: error: cannot find symbol
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
^
symbol: variable encryptedValue
location: class encryptData
/tmp/java_Ramvov/encryptData.java:16: error: cannot find symbol
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
^
symbol: method encodeBase64(byte[])
location: class Base64
2 个错误
我对 Java 知之甚少。请帮忙
【问题讨论】:
-
String encryptedValue = new String(..你错过了声明部分 -
错误很明显 - encryptedValue 未定义。
标签: java encryption