小编use*_*404的帖子

线程"main"中的异常java.security.InvalidKeyException:非法的键大小或默认参数

下面的代码抛出此错误消息:

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)

java jce

10
推荐指数
1
解决办法
2万
查看次数

在Hai.main上的java.util.ArrayList.toArray(未知来源)的java.lang.System.arraycopy(Native Method)中的java.lang.ArrayStoreException(Hai.java:20)

执行下面的代码时出现以下错误...

我试图使用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)

java

0
推荐指数
1
解决办法
2327
查看次数

标签 统计

java ×2

jce ×1