Examples of Cipher


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.DECRYPT_MODE, publicKey);

      byte[] blowfishKeyByteArray = cipher.doFinal(encryptedKey);
      blowfishKey = new SecretKeySpec(blowfishKeyByteArray, "Blowfish");
    } catch (Exception exception) {
      logger.error("[decryptBlowfishKey] Exception thrown.", exception);
    }
    return blowfishKey;
View Full Code Here

Examples of javax.crypto.Cipher

      Arrays.fill(zeros, (byte)0);
      IvParameterSpec ivSpec = new IvParameterSpec(zeros);
      ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
      serverProperties.store(byteArrayOutStream, "CentraView Server Properties");

      Cipher cipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding");
      cipher.init(Cipher.ENCRYPT_MODE, blowfishKey, ivSpec);

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

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

Examples of javax.crypto.Cipher

    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

Examples of javax.crypto.Cipher

          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

Examples of javax.crypto.Cipher

    // ����һ���ܳ׹�����Ȼ��������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

Examples of javax.crypto.Cipher

    // ����һ���ܳ׹�����Ȼ��������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

Examples of javax.crypto.Cipher

    // ����һ���ܳ׹�����Ȼ��������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

Examples of javax.crypto.Cipher

    // ����һ���ܳ׹�����Ȼ��������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

Examples of javax.crypto.Cipher

   
      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
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.