Package javax.crypto

Examples of javax.crypto.KeyGenerator


  private static final Key generateBlowfishKey()
  {
    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


    if ( transport.supportsStorage()){
     
      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

    RSAPublicKey  public_key )
 
    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

     *
     * @return a non null instance
     * @throws NoSuchAlgorithmException
     */
    protected SecretKey getEncryptionKey() throws NoSuchAlgorithmException {
        KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
        keyGen.init(RANDOM);
        return keyGen.generateKey();
    }
View Full Code Here

     */
    @PostConstruct
    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

    protected static SecretKey generateMacKey(String algorithm, int keySize)
    {
        try
        {
            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

    private byte[] encryptedKey;

    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);
    }
View Full Code Here

   * 生成256位AES对称加密算法的密钥
   * @return
   */
  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

      scipher.init(Cipher.DECRYPT_MODE, serverKey);
      String theMsg = (String) msg.getObject(scipher);
      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

Related Classes of javax.crypto.KeyGenerator

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.