/** * Creates a new instance with the given parameters. * * @param alg Symmetric algorithm used for encryption/decryption. * @param digest Key generation function digest. * @param params Key generation function salt and iteration count. */ public PBES1EncryptionScheme( final SymmetricAlgorithm alg, final DigestAlgorithm digest, final PBEParameter params) { boolean valid = false; for (PBES1Algorithm a : PBES1Algorithm.values()) { if (a.getDigest().getAlgorithm().equals(digest.getAlgorithm()) && a.getSpec().getName().equals(alg.getAlgorithm()) && a.getSpec().getMode().equals(alg.getMode()) && a.getSpec().getPadding().equals(alg.getPadding())) { valid = true; break; } } if (!valid) { throw new IllegalArgumentException("Invalid digest/cipher combination."); } setCipher(alg); generator = new PBKDF1KeyGenerator(digest, params.getSalt(), params.getIterationCount()); }
/** * Creates a new instance with the given parameters. * * @param alg Describes hash/algorithm pair suitable for PBES1 scheme. * @param params Key generation function salt and iteration count. */ public PBES1EncryptionScheme(final PBES1Algorithm alg, final PBEParameter params) { setCipher(SymmetricAlgorithm.newInstance(alg.getSpec())); generator = new PBKDF1KeyGenerator(alg.getDigest(), params.getSalt(), params.getIterationCount()); }