Package javax.crypto

Examples of javax.crypto.Cipher.doFinal()


    encrypt.setObserver(observer);
   
    encrypt.keyServer = true;
    String messageText = "hello this is a test message";
    Cipher cipher = encrypt2.getSymEncodingCipher();
    byte[] encodedBytes = cipher.doFinal(messageText.getBytes());
    assertNotSame(new String(encodedBytes),messageText);
   
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.reset();
    digest.update(encrypt.getDesKey().getEncoded());
View Full Code Here


    encrypt.setObserver(observer);
   
    encrypt.keyServer = true;
    String messageText = "hello this is a test message";
    Cipher cipher = encrypt2.getSymEncodingCipher();
    byte[] encodedBytes = cipher.doFinal(messageText.getBytes());
    assertNotSame(new String(encodedBytes),messageText);
   
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.reset();
    digest.update(encrypt2.getDesKey().getEncoded());
View Full Code Here

    encrypt.setObserver(observer);
   
    encrypt.keyServer = true;
    String messageText = "hello this is a test message";
    Cipher cipher = encrypt2.getSymEncodingCipher();
    byte[] encodedBytes = cipher.doFinal(messageText.getBytes());
    assertNotSame(new String(encodedBytes),messageText);
   
    Message msg = new Message(null,null,encodedBytes);
    Event event = new Event(Event.MSG,msg);
    encrypt.up(event);
View Full Code Here

    byte[] salt = generateSalt(saltSize);
    Cipher cipher = buildCipher(passphrase, salt, Cipher.ENCRYPT_MODE);

    byte[] plaintext = CryptoUtils.toBytesUtf8(plaintextString);
    byte[] ciphertext = cipher.doFinal(plaintext);

    // We record the salt length, then the salt, then the ciphertext
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(salt.length);
    baos.write(salt);
View Full Code Here

    if (ciphertextLength != bais.read(ciphertext)) {
      throw new IllegalArgumentException();
    }

    Cipher cipher = buildCipher(passphrase, salt, Cipher.DECRYPT_MODE);
    byte[] plaintext = cipher.doFinal(ciphertext);

    return new String(plaintext, "UTF8");
  }

  private String removeDecoration(String s) {
View Full Code Here

  public static byte[] decrypt(PrivateKey key, byte[] cipherText) {
    try {
      Cipher cipher = Cipher.getInstance(key.getAlgorithm());
      cipher.init(Cipher.DECRYPT_MODE, key);
      byte[] plainText = cipher.doFinal(cipherText);
      return plainText;
    } catch (GeneralSecurityException e) {
      throw new IllegalArgumentException("Error in decryption", e);
    }
  }
View Full Code Here

        try {
            Cipher aes = Cipher.getInstance("AES");
            if (keyHardware != null && keyHardware.length > 0) {
                try {
                    aes.init(Cipher.DECRYPT_MODE, new SecretKeySpec(pad(keyHardware), "AES"));
                    s = new String(aes.doFinal(Base64.decodeBase64(str)), "utf8");
                    if (s.startsWith("FDT:") && s.length() > 4) {
                        return s.split(":", 2)[1];// it was decrypted with HW UUID
                    }
                } catch (Exception e) {
                    Logger.logDebug("foo", e);
View Full Code Here

                }
            }

            // did not open, try again with old mac based key
            aes.init(Cipher.DECRYPT_MODE, new SecretKeySpec(pad(keyMac), "AES"));
            s = new String(aes.doFinal(Base64.decodeBase64(str)), "utf8");
            if (s.startsWith("FDT:") && s.length() > 4) {
                return s.split(":", 2)[1];//we don't want the decryption test
            } else {
                return decryptLegacy(str, keyMac);
            }
View Full Code Here

        byte[] keyHardware = OSUtils.getHardwareID();
        try {
            Cipher aes = Cipher.getInstance("AES");
            if (keyHardware != null && keyHardware.length > 0) {
                aes.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(pad(keyHardware), "AES"));
                return Base64.encodeBase64String(aes.doFinal(("FDT:" + str).getBytes("utf8")));
            }
            aes.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(pad(keyMac), "AES"));
            return Base64.encodeBase64String(aes.doFinal(("FDT:" + str).getBytes("utf8")));
        } catch (Exception e) {
            Logger.logError("Error Encrypting information, reverting to legacy format", e);
View Full Code Here

            if (keyHardware != null && keyHardware.length > 0) {
                aes.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(pad(keyHardware), "AES"));
                return Base64.encodeBase64String(aes.doFinal(("FDT:" + str).getBytes("utf8")));
            }
            aes.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(pad(keyMac), "AES"));
            return Base64.encodeBase64String(aes.doFinal(("FDT:" + str).getBytes("utf8")));
        } catch (Exception e) {
            Logger.logError("Error Encrypting information, reverting to legacy format", e);
            return encryptLegacy(str, keyMac);
        }
    }
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.