Package javax.crypto

Examples of javax.crypto.KeyGenerator.generateKey()


  {
    Key key = null;
    try {
      KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
      keyGenerator.init(128);
      key = keyGenerator.generateKey();
    } catch (Exception e) {
      logger.error("[generateBlowfishKey] Exception thrown.", e);
    }
    return key;
  } //end of generateBlowfishKey method
View Full Code Here


      try{
        spoof_cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
     
        KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
     
        spoof_key = keyGen.generateKey();
 
      }catch( Throwable e ){
       
        Debug.printStackTrace( e );
       
View Full Code Here

    throws IOException
  {
    try{
      KeyGenerator secret_key_gen = KeyGenerator.getInstance("DESede");
   
      session_key = secret_key_gen.generateKey();
       
      byte[] secret_bytes = session_key.getEncoded();
     
      try{
        Cipher  rsa_cipher = Cipher.getInstance( "RSA" );
View Full Code Here

     * @throws NoSuchAlgorithmException
     */
    protected SecretKey getEncryptionKey() throws NoSuchAlgorithmException {
        KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
        keyGen.init(RANDOM);
        return keyGen.generateKey();
    }

    @Override
    @SuppressWarnings("unchecked")
    public final <T> T encrypt(T object) {
View Full Code Here

    public final DES3CiphererDecipherer init() throws Exception {
        Security.addProvider(new BouncyCastleProvider());
        cipherer = Cipher.getInstance("DESede/ECB/PKCS5Padding", "BC");
        KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
        keyGen.init(168);
        SecretKey key = keyGen.generateKey();
        cipherer.init(Cipher.ENCRYPT_MODE, key);
        decipherer = Cipher.getInstance("DESede/ECB/PKCS5Padding", "BC");
        decipherer.init(Cipher.DECRYPT_MODE, key);
        if (log.isDebugEnabled()) log.debug("Cryptography loaded with [DESede/ECB/PKCS5Padding] algorityhms and initialized");
        return this;
View Full Code Here

        {
            KeyGenerator keyGen = KeyGenerator.getInstance(algorithm);

            keyGen.init(keySize);

            return keyGen.generateKey();
        }
        catch (NoSuchAlgorithmException e)
        {
            _log.error("Unsupported algorithm: " + algorithm + ", size: " + keySize, e);
            return null;
View Full Code Here

    public EncryptedKey(char[] password)
            throws Exception {

        KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_ALGORITHM);
        keyGen.init(KEY_SIZE);
        SecretKey key = keyGen.generateKey();
        this.secretKey = key;
        this.encryptedKey = getEncrypted(secretKey.getEncoded(), password);
    }

    public EncryptedKey(byte[] encryptedKey, char[] password) {
View Full Code Here

   */
  public static byte[] createAESKey() {
    try {
          KeyGenerator kgen = KeyGenerator.getInstance("AES");
          kgen.init(0x100);
          SecretKey skey = kgen.generateKey();
          return skey.getEncoded();
        } catch (NoSuchAlgorithmException e) {
           throw new IllegalArgumentException("Cannot find key generator: AES", e);
        }
  }
View Full Code Here

      System.out.println("Decrypted: "+theMsg);

      // Try a key that should fail
      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
      kgen.init(320);
      SecretKey key = kgen.generateKey();
      cipher.init(Cipher.DECRYPT_MODE, key);
      try
      {
         String tmp = (String) msg.getObject(cipher);
         throw new IllegalArgumentException("Should have failed to decrypt the msg");
View Full Code Here

   static void testKey() throws Exception
   {
      int size = 8 * 24;
      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
      kgen.init(size);
      SecretKey key = kgen.generateKey();
      byte[] kbytes = key.getEncoded();
      System.out.println("key.Algorithm = "+key.getAlgorithm());
      System.out.println("key.Format = "+key.getFormat());
      System.out.println("key.Encoded Size = "+kbytes.length);
     
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.