List of usage examples for org.bouncycastle.crypto BlockCipher getAlgorithmName
public String getAlgorithmName();
From source file:freenet.crypt.OCBBlockCipher_v149.java
License:Open Source License
public OCBBlockCipher_v149(BlockCipher hashCipher, BlockCipher mainCipher) { if (hashCipher == null) { throw new IllegalArgumentException("'hashCipher' cannot be null"); }//from w w w . j ava2 s.co m if (hashCipher.getBlockSize() != BLOCK_SIZE) { throw new IllegalArgumentException("'hashCipher' must have a block size of " + BLOCK_SIZE); } if (mainCipher == null) { throw new IllegalArgumentException("'mainCipher' cannot be null"); } if (mainCipher.getBlockSize() != BLOCK_SIZE) { throw new IllegalArgumentException("'mainCipher' must have a block size of " + BLOCK_SIZE); } if (!hashCipher.getAlgorithmName().equals(mainCipher.getAlgorithmName())) { throw new IllegalArgumentException("'hashCipher' and 'mainCipher' must be the same algorithm"); } this.hashCipher = hashCipher; this.mainCipher = mainCipher; }
From source file:org.cryptacular.generator.SecretKeyGenerator.java
License:Open Source License
/** * Generates a symmetric encryption key of the given length. * * @param bitLength Desired key length in bits. * @param cipher Cipher with with key will be used. * @param random Randomness provider for key generation. * * @return Symmetric encryption key./* w w w. j a v a 2 s . c o m*/ */ public static SecretKey generate(final int bitLength, final BlockCipher cipher, final SecureRandom random) { // Round up for bit lengths that are not a multiple of 8 final byte[] key = new byte[(bitLength + 7) / 8]; random.nextBytes(key); return new SecretKeySpec(key, cipher.getAlgorithmName()); }