Package javax.crypto

Examples of javax.crypto.Cipher


    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);

      returnByteArray = cipher.doFinal(blowfishKey.getEncoded());
    } catch (Exception exception) {
      logger.error("[encryptBlowfishKey] Exception thrown.", exception);
    }
    return returnByteArray;
  } //end of encryptServerData method
View Full Code Here


    PBEKeySpec keySpec = new PBEKeySpec(this.pbepass);
    SecretKeyFactory factory = SecretKeyFactory.getInstance(this.pbealgo);
    SecretKey cipherKey = factory.generateSecret(keySpec);
    // Decode the secret
    byte[] encoding = Base64Utils.fromb64(secret);
    Cipher cipher = Cipher.getInstance(this.pbealgo);
    cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
    byte[] decode = cipher.doFinal(encoding);
    return new String(decode).toCharArray();
  }
View Full Code Here

          SecretKeySpec  secret_key_spec2 = new SecretKeySpec(shared_secret, 8, 16, "AES" );
           
          AlgorithmParameterSpec  param_spec1 =   new IvParameterSpec( AES_IV1);
          AlgorithmParameterSpec  param_spec2 =   new IvParameterSpec( AES_IV2);     
             
          Cipher cipher1 = Cipher.getInstance( "AES/CBC/PKCS5Padding" );
          Cipher cipher2 = Cipher.getInstance( "AES/CBC/PKCS5Padding" );
           
          if ( connection.isIncoming()){
           
              cipher1.init( Cipher.ENCRYPT_MODE, secret_key_spec1, param_spec1 );
              cipher2.init( Cipher.DECRYPT_MODE, secret_key_spec2, param_spec2 );
             
              incoming_cipher  = cipher2;
              outgoing_cipher  = cipher1;
             
          }else{
           
              cipher1.init( Cipher.DECRYPT_MODE, secret_key_spec1, param_spec1 );
              cipher2.init( Cipher.ENCRYPT_MODE, secret_key_spec2, param_spec2 );
             
              incoming_cipher  = cipher1;
              outgoing_cipher  = cipher2;
          }
View Full Code Here

    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
    // ��ʽִ�м��ܲ���
    return cipher.doFinal(src);
  }
View Full Code Here

    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
    // ��ʽִ�н��ܲ���
    return cipher.doFinal(src);
  }
View Full Code Here

    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
    // ��ʽִ�м��ܲ���
    return cipher.doFinal(src);
  }
View Full Code Here

    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
    // ��ʽִ�н��ܲ���
    return cipher.doFinal(src);
  }
View Full Code Here

   
      SecretKey key = keyFactory.generateSecret(keySpec);
   
      PBEParameterSpec paramSpec = new PBEParameterSpec( salt, PBE_ITERATIONS );
   
      Cipher cipher = Cipher.getInstance( PBE_ALG );
     
      cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
 
      byte[]  enc = cipher.doFinal( data );
     
      byte[]  res = new byte[salt.length + enc.length];
     
      System.arraycopy( salt, 0, res, 0, salt.length );
     
View Full Code Here

 
      SecretKey key = keyFactory.generateSecret(keySpec);
 
      PBEParameterSpec paramSpec = new PBEParameterSpec(salt, PBE_ITERATIONS);
 
      Cipher cipher = Cipher.getInstance( PBE_ALG );
     
      cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
 
      fail_is_pw_error = true;
     
      return( cipher.doFinal( data, 8, data.length-8 ));
     
    }catch( Throwable e ){
     
      if ( fail_is_pw_error ){
       
View Full Code Here

      session_key = secret_key_gen.generateKey();
       
      byte[] secret_bytes = session_key.getEncoded();
     
      try{
        Cipher  rsa_cipher = Cipher.getInstance( "RSA" );
       
        rsa_cipher.init( Cipher.ENCRYPT_MODE, public_key );
       
        encryped_session_key = rsa_cipher.doFinal( secret_bytes );
       
      }catch( Throwable e ){
       
          // fallback to the BC implementation for jdk1.4.2 as JCE RSA not available
       
View Full Code Here

TOP

Related Classes of javax.crypto.Cipher

Copyright © 2018 www.massapicom. 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.