Package javax.crypto

Examples of javax.crypto.BadPaddingException


     * Test for <code>BadPaddingException(String)</code> constructor
     * Assertion: constructs BadPaddingException when <code>msg</code> is null
     */
    public void testBadPaddingException03() {
        String msg = null;
        BadPaddingException tE = new BadPaddingException(msg);
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    }
View Full Code Here


    /**
     * Test for <code>BadPaddingException()</code> constructor Assertion:
     * constructs BadPaddingException with no detail message
     */
    public void testBadPaddingException01() {
        BadPaddingException tE = new BadPaddingException();
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    }
View Full Code Here

     * Test for <code>BadPaddingException(String)</code> constructor
     * Assertion: constructs BadPaddingException with detail message msg.
     * Parameter <code>msg</code> is not null.
     */
    public void testBadPaddingException02() {
        BadPaddingException tE;
        for (int i = 0; i < msgs.length; i++) {
            tE = new BadPaddingException(msgs[i]);
            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
                    .getMessage(), msgs[i]);
            assertNull("getCause() must return null", tE.getCause());
        }
    }
View Full Code Here

     * Test for <code>BadPaddingException(String)</code> constructor
     * Assertion: constructs BadPaddingException when <code>msg</code> is null
     */
    public void testBadPaddingException03() {
        String msg = null;
        BadPaddingException tE = new BadPaddingException(msg);
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    }
View Full Code Here

    public static String[] msgs = {
            "New message",
            "Long message for Exception. Long message for Exception. Long message for Exception." };

    protected Object[] getData() {
        return new Object[] { new BadPaddingException(),
                new BadPaddingException(null), new BadPaddingException(msgs[1]) };
    }
View Full Code Here

            return cipher.processBlock(buf, 0, buf.length);
        }
        catch (InvalidCipherTextException e)
        {
            throw new BadPaddingException(e.getMessage());
        }
    }
View Full Code Here

            return buf.length;
        }
        catch (InvalidCipherTextException e)
        {
            throw new BadPaddingException(e.getMessage());
        }
    }
View Full Code Here

            return cipher.processBlock(bytes, 0, bytes.length);
        }
        catch (InvalidCipherTextException e)
        {
            throw new BadPaddingException(e.getMessage());
        }
    }
View Full Code Here

            out = cipher.processBlock(bytes, 0, bytes.length);
        }
        catch (InvalidCipherTextException e)
        {
            throw new BadPaddingException(e.getMessage());
        }

        for (int i = 0; i != out.length; i++)
        {
            output[outputOffset + i] = out[i];
View Full Code Here

        return handshakeHash;
    }

    void decrypt(MAC signer, CipherBox box) throws BadPaddingException {

        BadPaddingException reservedBPE = null;
        int tagLen = signer.MAClen();
        int cipheredLength = count - headerSize;

        if (!box.isNullCipher()) {
            // sanity check length of the ciphertext
            if (!box.sanityCheck(tagLen, cipheredLength)) {
                throw new BadPaddingException(
                    "ciphertext sanity check failed");
            }

            try {
                // Note that the CipherBox.decrypt() does not change
                // the capacity of the buffer.
                count = headerSize +
                        box.decrypt(buf, headerSize, cipheredLength, tagLen);
            } catch (BadPaddingException bpe) {
                // RFC 2246 states that decryption_failed should be used
                // for this purpose. However, that allows certain attacks,
                // so we just send bad record MAC. We also need to make
                // sure to always check the MAC to avoid a timing attack
                // for the same issue. See paper by Vaudenay et al and the
                // update in RFC 4346/5246.
                //
                // Failover to message authentication code checking.
                reservedBPE = bpe;
            }
        }

        if (tagLen != 0) {
            int macOffset = count - tagLen;
            int contentLen = macOffset - headerSize;

            // Note that although it is not necessary, we run the same MAC
            // computation and comparison on the payload for both stream
            // cipher and CBC block cipher.
            if (contentLen < 0) {
                // negative data length, something is wrong
                if (reservedBPE == null) {
                    reservedBPE = new BadPaddingException("bad record");
                }

                // set offset of the dummy MAC
                macOffset = headerSize + cipheredLength - tagLen;
                contentLen = macOffset - headerSize;
            }

            count -= tagLen;  // Set the count before any MAC checking
                              // exception occurs, so that the following
                              // process can read the actual decrypted
                              // content (minus the MAC) in the fragment
                              // if necessary.

            // Run MAC computation and comparison on the payload.
            if (checkMacTags(contentType(),
                    buf, headerSize, contentLen, signer, false)) {
                if (reservedBPE == null) {
                    reservedBPE = new BadPaddingException("bad record MAC");
                }
            }

            // Run MAC computation and comparison on the remainder.
            //
View Full Code Here

TOP

Related Classes of javax.crypto.BadPaddingException

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.