下面的代码抛出此错误消息:
Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters
Cipher dcipher;
byte[] salt = new String("12345678").getBytes();
int iterationCount = 1024;
int keyStrength = 256;
SecretKey key;
byte[] iv;
Decrypter(String passPhrase) throws Exception {
SecretKeyFactory factory = SecretKeyFactory
.getInstance("PBKDF2WithHmacSHA1");
System.out.println("factory +" + factory);
KeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), salt,
iterationCount, keyStrength);
System.out.println("spec " + spec);
SecretKey tmp = factory.generateSecret(spec);
System.out.println();
key = new SecretKeySpec(tmp.getEncoded(), "AES");
dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
}
public String encrypt(String data) throws Exception {
dcipher.init(Cipher.ENCRYPT_MODE, key); …Run Code Online (Sandbox Code Playgroud) 执行下面的代码时出现以下错误...
我试图使用List集合的toArray()方法将Object数组列表转换为BigDecimal数组.
当我只是给fileFormatObj.toArray()它工作正常,但是当我在下面的代码中给出时,我收到错误....
public static void main(String[] args)
{
List<BigDecimal> objList = new ArrayList<BigDecimal>();
List<Object[]> fileFormatObj = new ArrayList<Object[]>();
final Object[] array1 = new Object[1];
array1[0] = new BigDecimal(BigInteger.ONE);
fileFormatObj.add(array1);
if (fileFormatObj != null)
{
//Error here java.lang.System.arraycopy
final BigDecimal[] arr = fileFormatObj
.toArray(new BigDecimal[fileFormatObj.size()]);
objList.addAll(Arrays.asList(arr));
for (final BigDecimal object : arr) {
System.out.println("TEST-->" + object.intValue());
}
}
}
Run Code Online (Sandbox Code Playgroud)