List of usage examples for javax.crypto KeyGenerator init
public final void init(int keysize)
From source file:com.github.woki.payments.adyen.action.CSEUtil.java
private static SecretKey aesKey(int keySize) throws NoSuchAlgorithmException { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(keySize); return kgen.generateKey(); }
From source file:de.hybris.platform.b2b.punchout.services.impl.SymmetricManager.java
public static String getKey() { String key = null;/*from w ww .j a va 2 s . co m*/ try { final KeyGenerator kgen = KeyGenerator.getInstance(ALGORITHM); kgen.init(KEY_SIZE); // Generate the secret key specs. final SecretKey skey = kgen.generateKey(); final byte[] raw = skey.getEncoded(); key = new Base64().encodeAsString(raw); } catch (final NoSuchAlgorithmException e) { // should never happen LOG.error("System was unable to generate the key.", e); } return key; }
From source file:br.com.manish.ahy.kernel.util.HashUtil.java
private static Cipher getCipher(boolean enc) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKeySpec skeySpec = new SecretKeySpec(getBytes(HEXES2), "AES"); Cipher cipher = Cipher.getInstance("AES"); if (enc) {/* ww w.j a va 2s .com*/ cipher.init(Cipher.ENCRYPT_MODE, skeySpec); } else { cipher.init(Cipher.DECRYPT_MODE, skeySpec); } return cipher; }
From source file:models.logic.CipherDecipher.java
public static SecretKey generateKey() throws NoSuchAlgorithmException { KeyGenerator keyGenS = KeyGenerator.getInstance("AES"); keyGenS.init(128); SecretKey sKey = keyGenS.generateKey(); return sKey;/*from w w w.j a va 2s .c o m*/ }
From source file:org.apache.abdera.security.util.KeyHelper.java
public static Key generateKey(String type) throws NoSuchAlgorithmException { KeyGenerator keygen = KeyGenerator.getInstance(type); keygen.init(new SecureRandom()); return keygen.generateKey(); }
From source file:org.apache.abdera.security.util.KeyHelper.java
public static SecretKey generateSecretKey(String type, int size) throws NoSuchAlgorithmException, NoSuchProviderException { KeyGenerator keyGenerator = KeyGenerator.getInstance(type); keyGenerator.init(size); return keyGenerator.generateKey(); }
From source file:org.craftercms.commons.crypto.CipherUtils.java
/** * Generates a random encryption key./*from www . ja va 2s. c o m*/ * * @param cipherAlgorithm the cipher algorithm the key will be used with. Will determine the key size * @return the generated key */ public static SecretKey generateKey(String cipherAlgorithm) throws NoSuchAlgorithmException { KeyGenerator keyGenerator = KeyGenerator.getInstance(cipherAlgorithm); keyGenerator.init(CryptoUtils.secureRandom); return keyGenerator.generateKey(); }
From source file:cl.niclabs.tscrypto.common.messages.EncryptedData.java
private static SecretKeySpec generateAESKey() { SecretKeySpec skeySpec = null; try {/*from ww w . j a va 2 s.c o m*/ KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(KEYSIZE_AES); // Generate the secret key specs. SecretKey secretKey = keyGen.generateKey(); skeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return skeySpec; }
From source file:org.demo.show.providers.ThreeDes2.java
/** * //w ww . j a v a2 s .c o m * ? * * @return byte[] * */ public static byte[] initkey() throws Exception { // ? KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); // ?? kg.init(168); // ? SecretKey secretKey = kg.generateKey(); // ??? return secretKey.getEncoded(); }
From source file:de.taimos.dvalin.interconnect.model.MessageCryptoUtil.java
private static void generateKey() { try {/*from ww w . jav a 2 s . co m*/ final KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); final SecretKey skey = kgen.generateKey(); System.out.println("Key: " + Hex.encodeHexString(skey.getEncoded())); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } }