Package javax.crypto

Examples of javax.crypto.Cipher.doFinal()


      SecretKey cipherKey, PBEParameterSpec cipherSpec)
      throws Exception
   {
      Cipher cipher = Cipher.getInstance(cipherAlgorithm);
      cipher.init(Cipher.ENCRYPT_MODE, cipherKey, cipherSpec);
      byte[] encoding = cipher.doFinal(secret);
      return encoding;
   }

   public static String encode64(byte[] secret, String cipherAlgorithm,
      SecretKey cipherKey, PBEParameterSpec cipherSpec)
View Full Code Here


    public static String encrypt(String plainText, String encryptionKey, String salt) {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
            SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
            cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
            return Hex.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")));
        } catch (Exception e) {
            LOG.error("Could not encrypt value.", e);
        }
            return null;
    }
View Full Code Here

    public static String decrypt(String cipherText, String encryptionKey, String salt) {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
            SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
            cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
            return new String(cipher.doFinal(Hex.decode(cipherText)), "UTF-8");
        } catch (Exception e) {
            LOG.error("Could not decrypt value.", e);
        }
        return null;
    }
View Full Code Here

      // Our cleartext as bytes
      byte[] cleartext = source.getBytes();

      // Encrypt the cleartext
      byte[] ciphertext = desCipher.doFinal(cleartext);

      // Return a String representation of the cipher text
      return getString(ciphertext);
    } catch (Exception e) {
            Debug.error(e.toString());
View Full Code Here

      // Initialize the same cipher for decryption
      desCipher.init(Cipher.DECRYPT_MODE, key);

      // Decrypt the ciphertext
      byte[] cleartext = desCipher.doFinal(ciphertext);

      // Return the clear text
      return new String(cleartext);
    } catch (Exception e) {
            Debug.error(e.toString());
View Full Code Here

      
    String symVersion = new String(digest.digest(), "UTF-8");
   
    encrypt.keyServer = false;
    Message msg = new Message();
    msg.setBuffer(cipher.doFinal("hello".getBytes()));
    msg.putHeader(EncryptHeader.KEY, new EncryptHeader(
        EncryptHeader.ENCRYPT, symVersion));
   
    Event evt = new Event(Event.MSG,msg);
View Full Code Here

    // this should have changed us to the key server
    encrypt.up(event);
   
    // send another encrypted message
    Message msg2 = new Message();
    msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
    msg2.putHeader(EncryptHeader.KEY, new EncryptHeader(
        EncryptHeader.ENCRYPT, symVersion));
   
    // we should have three messages now in our observer
    // that are decrypted
View Full Code Here

    String symVersion = new String(digest.digest(), "UTF-8");
   
    // encrypt and send an initial message to peer
    Cipher cipher = server.getSymEncodingCipher();
    Message msg = new Message();
    msg.setBuffer(cipher.doFinal("hello".getBytes()));
    msg.putHeader(EncryptHeader.KEY, new EncryptHeader(
        EncryptHeader.ENCRYPT, symVersion));
   
    Event evt = new Event(Event.MSG,msg);
View Full Code Here

    // assert that both now have same key
    assertEquals(peer.getDesKey(),server.getDesKey());
   
    // send another encrypted message to peer to test queue
    Message msg2 = new Message();
    msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
    msg2.putHeader(EncryptHeader.KEY, new EncryptHeader(
        EncryptHeader.ENCRYPT, symVersion));
   
    Event evt2 = new Event(Event.MSG,msg2);
View Full Code Here

    encrypt.down(event);
    Message sentMsg = (Message)((Event)observer.getDownMessages().get("message0")).getArg();
    String encText = new String(sentMsg.getBuffer());
    assertNotSame(encText,messageText);
    Cipher cipher = encrypt2.getSymDecodingCipher();
    byte[] decodedBytes = cipher.doFinal(sentMsg.getBuffer());
    String temp = new String(decodedBytes);
    System.out.println("decoded text:" + temp);
    assertEquals(temp,messageText);

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