Java 8 KeyGenerator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 KeyGenerator class.

This code example shows how to use the following methods:generateKey, init
    } 
 
    private static void test(KeyGenerator kg, int major, int minor)
            throws Exception { 
 
        kg.init(new TlsRsaPremasterSecretParameterSpec(major, minor));
        SecretKey key = kg.generateKey();
        byte[] encoded = key.getEncoded();
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        } 
        if ((encoded[0] != major) || (encoded[1] != minor)) {
            throw new Exception("version mismatch: "  + encoded[0] +
                "." + encoded[1]);
        } 
        System.out.println("OK: " + major + "." + minor);
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, init, KeyGenerator.init
 
    private void checkResult(KeyGenerator keyGen) {
        AlgorithmParameterSpec paramsNull = null;
        AlgorithmParameterSpec params = new APSpec();
        try { 
            keyGen.init(0, new SecureRandom());
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e) {
        } 
        try { 
            keyGen.init(77, new SecureRandom());
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e) {
        } 
        keyGen.init(78, new SecureRandom());
        try { 
            keyGen.init(new SecureRandom());
            fail("IllegalArgumentException must be thrown");                
        } catch (IllegalArgumentException e) {
        } 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, KeyGenerator.init
                random = new SecureRandom();
            } 
 
            if (keySize < 0)
            { 
                keyGen.init(random);
            } 
            else 
            { 
                keyGen.init(keySize, random);
            } 
 
            cipher = helper.createCipher(encryptionOID);
            encKey = keyGen.generateKey();
            AlgorithmParameters params = helper.generateParameters(encryptionOID, encKey, random);
 
            try 
            { 
                cipher.init(Cipher.ENCRYPT_MODE, encKey, params, random);
            } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, init
        return seedKg.generateKey();
    } 
 
    public static SecretKey makeAESKey(int keySize)
    { 
        aesKg.init(keySize);
        return aesKg.generateKey();
    } 
 
    public static SecretKey makeCamelliaKey(int keySize)
    { 
        camelliaKg.init(keySize);
        return camelliaKg.generateKey();
    } 
 
    public static X509Certificate makeCertificate(KeyPair _subKP,
            String _subDN, KeyPair _issKP, String _issDN)
        throws GeneralSecurityException, IOException, OperatorCreationException 
    { 
        return makeCertificate(_subKP, _subDN, _issKP, _issDN, false);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, init
    } 
 
    private static void test(KeyGenerator kg, int major, int minor)
            throws Exception { 
 
        kg.init(new TlsRsaPremasterSecretParameterSpec(major, minor));
        SecretKey key = kg.generateKey();
        byte[] encoded = key.getEncoded();
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        } 
        if ((encoded[0] != major) || (encoded[1] != minor)) {
            throw new Exception("version mismatch: "  + encoded[0] +
                "." + encoded[1]);
        } 
        System.out.println("OK: " + major + "." + minor);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:init
   */ 
  private final KeyGenerator keyGen;
  { 
    try { 
      keyGen = KeyGenerator.getInstance(DEFAULT_HMAC_ALGORITHM);
      keyGen.init(KEY_LENGTH);
    } catch (NoSuchAlgorithmException nsa) {
      throw new IllegalArgumentException("Can't find " + DEFAULT_HMAC_ALGORITHM +
      " algorithm."); 
    } 
  } 
 
  /** 
   * Generate a new random secret key. 
   * @return the new key 
   */ 
  protected SecretKey generateSecret() {
    SecretKey key;
    synchronized (keyGen) {
      key = keyGen.generateKey();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey
        return kpg.generateKeyPair();
    } 
 
    public static SecretKey makeDesede128Key()
    { 
        return desede128kg.generateKey();
    } 
 
    public static SecretKey makeDesede192Key()
    { 
        return desede192kg.generateKey();
    } 
 
    public static SecretKey makeRC240Key()
    { 
        return rc240kg.generateKey();
    } 
 
    public static SecretKey makeRC264Key()
    { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:init
   */ 
  private final KeyGenerator keyGen;
  { 
    try { 
      keyGen = KeyGenerator.getInstance(DEFAULT_HMAC_ALGORITHM);
      keyGen.init(KEY_LENGTH);
    } catch (NoSuchAlgorithmException nsa) {
      throw new IllegalArgumentException("Can't find " + DEFAULT_HMAC_ALGORITHM +
      " algorithm."); 
    } 
  } 
 
  /** 
   * Generate a new random secret key. 
   * @return the new key 
   */ 
  protected SecretKey generateSecret() {
    SecretKey key;
    synchronized (keyGen) {
      key = keyGen.generateKey();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, init
    private transient Key key;
    private Cipher cipher;
 
    public JavaAES() throws Exception{ 
	keyGen = KeyGenerator.getInstance("AES");
	keyGen.init(128);
	key = keyGen.generateKey();
	if(DEBUG==1){System.out.println("Generated AES Key = "+new String(key.getEncoded(),"UTF8") + "\r\nKey Algorithm="+key.getAlgorithm());}
	cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    } 
 
    public byte[] encrypt(String plainText) throws Exception{
	cipher.init(Cipher.ENCRYPT_MODE,key);
	output = cipher.doFinal(plainText.getBytes());
	if(DEBUG==1){System.out.println("Cipher Text: " + new String(output,"UTF8"));}
	if(DEBUG==1){System.out.println("Cipher IV: "+new String(cipher.getIV(),"UTF8"));}
	IV = cipher.getIV();
	return output;
    } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:generateKey, init
	} 
 
	private boolean internalGenerateKeySize(KeyGenerator kgen, int nBits) {
 
		boolean ret = false;
		kgen.init(nBits);
 
		// Generate the secret key specs. 
		SecretKey skey = kgen.generateKey();
		byte[] rawKey = skey.getEncoded();
		m_skeySpec = new SecretKeySpec(rawKey, "AES");
 
		try { 
			Cipher cipher = Cipher.getInstance("AES");
			cipher.init(Cipher.ENCRYPT_MODE, m_skeySpec);
			ret = true;
		} catch (Exception e) {
			m_skeySpec = null;
		} 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 KeyGenerator Questions & Answers:

See Code Examples for Java 8 KeyGenerator Methods: