Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中带有河豚的cipher.getInstance()_Java - Fatal编程技术网

java中带有河豚的cipher.getInstance()

java中带有河豚的cipher.getInstance(),java,Java,你好,我的代码没有给我任何错误,但也不工作 我不知道这是什么问题,但我认为这是在Cipher.getInstance private static void createKey(char[] password) throws Exception { System.out.println("Generating a Blowfish key..."); // Create a blowfish key KeyGenerator keyGenerator = KeyGene

你好,我的代码没有给我任何错误,但也不工作

我不知道这是什么问题,但我认为这是在
Cipher.getInstance

private static void createKey(char[] password) throws Exception {
    System.out.println("Generating a Blowfish key...");

    // Create a blowfish key
    KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
    keyGenerator.init(256);
    Key key = keyGenerator.generateKey();

    System.out.println("Done generating the key.");

    // Now we need to create the file with the key,
    // encrypting it with a password.
    byte[] salt = new byte[8];
    SecureRandom random = new SecureRandom();
    random.nextBytes(salt);
    PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHAAndTwofish-CBC");
    SecretKey pbeKey = keyFactory.generateSecret(pbeKeySpec);
    PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, ITERATIONS);

    //Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES-CBC");
    //Cipher cipher = Cipher.getInstance("PBEWithSHAAndTwofish-CBC");
    Cipher cipher = Cipher.getInstance("PBEWithSHAAndTwofish-CBC");

    cipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

    // Encrypt the key
    byte[] encryptedKeyBytes = cipher.doFinal(key.getEncoded());

    // Write out the salt, and then the encrypted key bytes
    FileOutputStream fos = new FileOutputStream(KEY_FILENAME);
    fos.write(salt);
    fos.write(encryptedKeyBytes);
    fos.close();
}

定义“不工作”。它会运行,但在完成任务之前会退出