Package javax.crypto

Examples of javax.crypto.Cipher.update()


      SecretKeySpec skeySpec = new SecretKeySpec(shared, "AES");
      aes.init(Cipher.ENCRYPT_MODE, skeySpec);

      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      for (byte b : data.getBytes("utf8")) {
        aes.update(new byte[] { b });
        buffer.write(aes.doFinal());
      }
      data = null;
      payload = buffer.toByteArray();
      // TODO Change this part to per-char encryption
View Full Code Here


      ByteArrayInputStream input = new ByteArrayInputStream(payload);
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      SecretKeySpec skeySpec = new SecretKeySpec(shared, "AES");
      aes.init(Cipher.DECRYPT_MODE, skeySpec);
      while (input.read(buffer) > 0) {
        aes.update(buffer);
        output.write(aes.doFinal()[0]);
      }
      String result = new String(output.toByteArray(), "utf8");
      return result;
    } catch (Exception e) {
View Full Code Here

        byte[] input = new byte[64];
        int bytesRead;
        while ((bytesRead = inFile.read(input)) != -1)
        {
           byte[] output = cipher.update(input, 0, bytesRead);
           if (output != null) outFile.write(output);
        }

        byte[] output = cipher.doFinal();
        if (output != null) outFile.write(output);
View Full Code Here

        Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
        cipher.init(Cipher.DECRYPT_MODE, passwordKey, parameterSpec);
        byte[] input = new byte[64];
        int bytesRead;
        while ((bytesRead = inFile.read(input)) != -1) {
          byte[] output = cipher.update(input, 0, bytesRead);
            if (output != null)
              outFile.write(output);
        }
        byte[] output = cipher.doFinal();
        if (output != null)
View Full Code Here

            byte[] keyBytes = key.getEncoded();
            byte[] data = s.getBytes("utf-8");
            ByteArrayOutputStream out = new ByteArrayOutputStream(keyBytes.length + data.length);
            out.write(keyBytes);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            out.write(cipher.update(data));
            out.write(cipher.doFinal());
            StringBuilder ret = new StringBuilder(PREFIX);
            for (byte b: out.toByteArray()) {
                ret.append(Text.hexTable[b>>4 & 0x0f]).append(Text.hexTable[b&0x0f]);
            }
View Full Code Here

            }
            SecretKeySpec key = new SecretKeySpec(data, 0, KEY_LENGTH, "DES");
            Cipher cipher = Cipher.getInstance("DES");
            ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
            cipher.init(Cipher.DECRYPT_MODE, key);
            out.write(cipher.update(data, KEY_LENGTH, data.length - KEY_LENGTH));
            out.write(cipher.doFinal());
            return out.toString("utf-8");
        } catch (Exception e) {
            log.warn("Unable to decrypt data: " + e);
            return null;
View Full Code Here

            Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
            SecretKey key = getKeyFromPassphrase(passphrase, iv, 24);
            cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));

            byte[] plain = new byte[payload.length];
            cipher.update(payload, 0, payload.length, plain, 0);

            return plain;
        } else {
            return payload;
        }
View Full Code Here

        Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
        SecretKey key = getKeyFromPassphrase(passphrase, iv, 24);
        cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));

        byte[] encrypted = new byte[payload.length];
        cipher.update(payload, 0, payload.length, encrypted, 0);
        setPayload(encrypted);
    }

    /**
     *
 
View Full Code Here

                // int inputOffset, int inputLen, byte[] output, int
                // outputOffset)
                // throws ShortBufferException - if the given output buffer is
                // too
                // small to hold the result
                ecipher.update(new byte[20], 0, 20, cipherText);
               
                fail("failed exception test - no ShortBufferException thrown");
            }
            catch (ShortBufferException e)
            {
View Full Code Here

                // int inputOffset, int inputLen, byte[] output, int
                // outputOffset)
                // throws ShortBufferException - if the given output buffer is
                // too
                // small to hold the result
                ecipher.update(new byte[20], 0, 20, cipherText);
               
                fail("failed exception test - no ShortBufferException thrown");
            }
            catch (ShortBufferException e)
            {
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.