Package javax.crypto

Examples of javax.crypto.Cipher.update()


                        byte[] exchangedKey = new byte[16];
                        try {
                            Cipher rc4 = Cipher.getInstance("RC4");
                            rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(userSessionKey, "RC4"));
                            rc4.update(masterKey, 0, 16, exchangedKey, 0);
                        } catch (GeneralSecurityException gse) {
                            throw new RuntimeException("", gse);
                        }

                        setSessionKey(exchangedKey);
View Full Code Here


                 */
                byte[] exchangedKey = new byte[16];
                try {
                    Cipher rc4 = Cipher.getInstance("RC4");
                    rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(userSessionKey, "RC4"));
                    rc4.update(masterKey, 0, 16, exchangedKey, 0);
                } catch (GeneralSecurityException gse) {
                    throw new RuntimeException("", gse);
                }

                setSessionKey(exchangedKey);
View Full Code Here

            if (serializedData != null) {
                int numBytes;
                byte[] buf = new byte[8192];
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while ((numBytes = serializedData.read(buf)) != -1) {
                    byte[] data = c.update(buf, 0, numBytes);
                    baos.write(data);
                }
                baos.write(c.doFinal());
                encryptedBytes = baos.toByteArray();
            } else {
View Full Code Here

        // ... Actually, no. BouncyCastle's CTR breaks this assumption.
        // You must handle when update() produce less than was in input.
        while (inputPtr < plaintext.length) {
          int max = plaintext.length - inputPtr;
          int count = (max == 1) ? 1 : (random.nextInt(max - 1) + 1);
          int moved = c.update(plaintext, inputPtr, count, output,
              outputPtr);
          outputPtr += moved;
          inputPtr += count;
        }
        c.doFinal(plaintext, 0, plaintext.length - inputPtr, output,
View Full Code Here

            throw new CHKDecodeException("Crypto key too short");
    try {
        Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(cryptoKey, "AES"), new IvParameterSpec(hash, 0, 16));
        byte[] plaintext = new byte[data.length + 2];
    int moved = cipher.update(data, 0, data.length, plaintext);
    cipher.doFinal(headers, hash.length+2, 2, plaintext, moved);
        int size = ((plaintext[data.length] & 0xff) << 8) + (plaintext[data.length + 1] & 0xff);
        if((size > 32768) || (size < 0)) {
            throw new CHKDecodeException("Invalid size: "+size);
        }
View Full Code Here

        // CTR mode IV is only 16 bytes.
        // That's still plenty though. It will still be unique.
        Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        cipher.init(Cipher.ENCRYPT_MODE, ckey, new IvParameterSpec(hash, 0, 16));
        byte[] cdata = new byte[data.length];
    int moved = cipher.update(data, 0, data.length, cdata);
    if (moved == data.length) {
      cipher.doFinal(tmpLen, 0, 2, header, hash.length+2);
    } else {
      // FIXME inefficient
      byte[] tmp = cipher.doFinal(tmpLen, 0, 2);
View Full Code Here

        rawModeTest("RIPEMD128withRSA", TeleTrusTObjectIdentifiers.ripemd128, priv2048Key, pub2048Key, random);

        // init reset test
        c.init(Cipher.ENCRYPT_MODE, pubKey, rand);

        out = c.update(new byte[40]);

        c.init(Cipher.ENCRYPT_MODE, pubKey, rand);

        out = c.update(new byte[40]);
    }
View Full Code Here

        out = c.update(new byte[40]);

        c.init(Cipher.ENCRYPT_MODE, pubKey, rand);

        out = c.update(new byte[40]);
    }

    private void oaepCompatibilityTest(String digest, PrivateKey privKey, PublicKey pubKey)
        throws Exception
    {
View Full Code Here

        //
        c = Cipher.getInstance("RSA", "BC");

        c.init(Cipher.ENCRYPT_MODE, pubKey, rand);

        c.update(input);

        out = c.doFinal();

        if (!areEqual(out, output[0]))
        {
View Full Code Here

        //
        c = Cipher.getInstance("RSA/NONE/NoPadding", "BC");

        c.init(Cipher.ENCRYPT_MODE, pubKey, rand);

        c.update(input);

        out = c.doFinal();

        if (!areEqual(out, output[0]))
        {
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.