Package javax.crypto

Examples of javax.crypto.BadPaddingException


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


                                      0, totalLen);

            if (padding != null) {
                int padStart = padding.unpad(outWithPadding, 0, totalLen);
                if (padStart < 0) {
                    throw new BadPaddingException("Given final block not "
                                                  + "properly padded");
                }
                totalLen = padStart;
            }
            if ((output.length - outputOffset) < totalLen) {
View Full Code Here

    /**
     * Pad the data and return the padded block.
     */
    public byte[] pad(byte[] data) throws BadPaddingException {
        if (data.length > maxDataSize) {
            throw new BadPaddingException("Data must be shorter than "
                + (maxDataSize + 1) + " bytes");
        }
        switch (type) {
        case PAD_NONE:
            return data;
View Full Code Here

    /**
     * Unpad the padded block and return the data.
     */
    public byte[] unpad(byte[] padded) throws BadPaddingException {
        if (padded.length != paddedSize) {
            throw new BadPaddingException("Padded length must be " + paddedSize);
        }
        switch (type) {
        case PAD_NONE:
            return padded;
        case PAD_BLOCKTYPE_1:
View Full Code Here

     * PKCS#1 v1.5 unpadding (blocktype 1 and 2).
     */
    private byte[] unpadV15(byte[] padded) throws BadPaddingException {
        int k = 0;
        if (padded[k++] != 0) {
            throw new BadPaddingException("Data must start with zero");
        }
        if (padded[k++] != type) {
            throw new BadPaddingException("Blocktype mismatch: " + padded[1]);
        }
        while (true) {
            int b = padded[k++] & 0xff;
            if (b == 0) {
                break;
            }
            if (k == padded.length) {
                throw new BadPaddingException("Padding string not terminated");
            }
            if ((type == PAD_BLOCKTYPE_1) && (b != 0xff)) {
                throw new BadPaddingException("Padding byte not 0xff: " + b);
            }
        }
        int n = padded.length - k;
        if (n > maxDataSize) {
            throw new BadPaddingException("Padding string too short");
        }
        byte[] data = new byte[n];
        System.arraycopy(padded, padded.length - n, data, 0, n);
        return data;
    }
View Full Code Here

    private byte[] unpadOAEP(byte[] padded) throws BadPaddingException {
        byte[] EM = padded;
        int hLen = lHash.length;

        if (EM[0] != 0) {
            throw new BadPaddingException("Data must start with zero");
        }

        int seedStart = 1;
        int seedLen = hLen;

        int dbStart = hLen + 1;
        int dbLen = EM.length - dbStart;

        mgf1(EM, dbStart, dbLen, EM, seedStart, seedLen);
        mgf1(EM, seedStart, seedLen, EM, dbStart, dbLen);

        // verify lHash == lHash'
        for (int i = 0; i < hLen; i++) {
            if (lHash[i] != EM[dbStart + i]) {
                throw new BadPaddingException("lHash mismatch");
            }
        }

        // skip over padding (0x00 bytes)
        int i = dbStart + hLen;
        while (EM[i] == 0) {
            i++;
            if (i >= EM.length) {
                throw new BadPaddingException("Padding string not terminated");
            }
        }

        if (EM[i++] != 1) {
            throw new BadPaddingException
                ("Padding string not terminated by 0x01 byte");
        }

        int mLen = EM.length - i;
        byte[] m = new byte[mLen];
View Full Code Here

            mgfMd.update(C);
            try {
                mgfMd.digest(digest, 0, digest.length);
            } catch (DigestException e) {
                // should never happen
                throw new BadPaddingException(e.toString());
            }
            for (int i = 0; (i < digest.length) && (maskLen > 0); maskLen--) {
                out[outOfs++] ^= digest[i++];
            }
            if (maskLen > 0) {
View Full Code Here

     */
    private static BigInteger parseMsg(byte[] msg, BigInteger n)
            throws BadPaddingException {
        BigInteger m = new BigInteger(1, msg);
        if (m.compareTo(n) >= 0) {
            throw new BadPaddingException("Message is larger than modulus");
        }
        return m;
    }
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

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.