Beispiel #1
0
  public static Cipher createCipher(
      CipherSpec cipherSpec, int cipherInitMode, SecretKey secretKey, byte[] iv)
      throws CipherException {
    logger.log(Level.INFO, "Creating cipher using " + cipherSpec + " ...");

    try {
      if (cipherSpec.needsUnlimitedStrength()) {
        CipherUtil.enableUnlimitedStrength();
      }

      Cipher cipher = Cipher.getInstance(cipherSpec.getAlgorithm(), PROVIDER);
      cipher.init(cipherInitMode, secretKey, new IvParameterSpec(iv));

      return cipher;
    } catch (Exception e) {
      throw new CipherException(e);
    }
  }