Example usage for javax.crypto IllegalBlockSizeException getMessage

List of usage examples for javax.crypto IllegalBlockSizeException getMessage

Introduction

In this page you can find the example usage for javax.crypto IllegalBlockSizeException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.hovans.netty.tcpsample.network.ChannelDecoder.java

@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws JSONException {

    PowerManager.WakeLock wakeLock = WakeLockWrapper.getWakeLockInstance(mContext,
            ChannelDecoder.class.getSimpleName());
    wakeLock.acquire();/*from   www .  j a v  a  2s . c  o  m*/

    try {
        //  ?? ?? ?? ? 
        if (buffer.readableBytes() < 4) {
            return null;
        }
        int nBodySize = buffer.getInt(0); // ? ??

        if (buffer.readableBytes() < nBodySize + 4) {
            return null;
        }

        // decoding
        buffer.skipBytes(4);

        byte[] recvBuff = new byte[nBodySize - 1];
        buffer.readBytes(recvBuff, 0, nBodySize - 1);
        buffer.skipBytes(1);

        byte[] decryptMessage;
        try {
            decryptMessage = mCipher.doFinal(recvBuff);
        } catch (IllegalBlockSizeException e) {
            LogByCodeLab.w("decrypt fail, cause" + e.getMessage());
            printPacket(recvBuff);
            channel.close();
            throw new RuntimeException("decrypt fail");
        } catch (BadPaddingException e) {
            LogByCodeLab.w("decrypt fail, cause" + e.getMessage());
            printPacket(recvBuff);
            channel.close();
            throw new RuntimeException("decrypt fail");
        }

        if (decryptMessage.length < 4) {
            channel.close();
            LogByCodeLab.w("decripted message should longer than 4 bytes, size = " + decryptMessage.length);
            throw new RuntimeException("decripted message should longer than 4 bytes");
        }

        ChannelBuffer cb = new BigEndianHeapChannelBuffer(decryptMessage);
        // int jsonLen = (decryptMessage[0] << 24) + (decryptMessage[1] <<
        // 16) +
        // (decryptMessage[2] << 8) + (decryptMessage[3]);
        int jsonLen = cb.readInt();

        String jsonString;
        try {
            jsonString = new String(decryptMessage, 4, jsonLen, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // ? ?, ? 
            throw new RuntimeException(e);
        }

        LogByCodeLab.i(String.format("READ  [%s]", jsonString));

        return new JSONObject(jsonString);
    } finally {
        wakeLock.release();
    }
}

From source file:be.fedict.commons.eid.consumer.BeIDIntegrity.java

/**
 * Verifies a non-repudiation signature.
 * /*from w  w  w .ja  va2 s.  c  om*/
 * @param expectedDigestValue
 * @param signatureValue
 * @param certificate
 * @return
 */
public boolean verifyNonRepSignature(final byte[] expectedDigestValue, final byte[] signatureValue,
        final X509Certificate certificate) {
    try {
        return __verifyNonRepSignature(expectedDigestValue, signatureValue, certificate);
    } catch (final InvalidKeyException ikex) {
        LOG.warn("invalid key: " + ikex.getMessage(), ikex);
        return false;
    } catch (final NoSuchAlgorithmException nsaex) {
        LOG.warn("no such algo: " + nsaex.getMessage(), nsaex);
        return false;
    } catch (final NoSuchPaddingException nspex) {
        LOG.warn("no such padding: " + nspex.getMessage(), nspex);
        return false;
    } catch (final BadPaddingException bpex) {
        LOG.warn("bad padding: " + bpex.getMessage(), bpex);
        return false;
    } catch (final IOException ioex) {
        LOG.warn("IO error: " + ioex.getMessage(), ioex);
        return false;
    } catch (final IllegalBlockSizeException ibex) {
        LOG.warn("illegal block size: " + ibex.getMessage(), ibex);
        return false;
    }
}

From source file:org.caboclo.util.Credentials.java

/**
 * Check if there are credentials previously stored on disk, for a specified
 * cloud provider/*w w w. j  a va 2 s  .c  om*/
 *
 * @param currentServer The cloud storage provider
 * @return Credentials for the specified cloud provider, that were
 * previously saved on file
 */
public String checkCredentialsFile(String currentServer) {
    StringBuilder path = new StringBuilder();
    path.append(System.getProperty("user.home")).append(java.io.File.separator).append("backupcredentials");

    File credentialsFile = new File(path.toString());
    BufferedReader input = null;
    String token = "";

    try {
        //Creates file only if it does not exist            
        boolean createdNow = credentialsFile.createNewFile();
        //Return with empty token, because file did not exist
        if (createdNow) {
            return token;
        }
        input = new BufferedReader(new FileReader(credentialsFile));
        String line;
        while (input.ready()) {
            line = input.readLine();
            if (line.startsWith(currentServer)) {
                int colon = line.indexOf(":");
                String encodedCred = line.substring(colon + 1);
                token = decryptCredentials(new Base64().decode(encodedCred.getBytes()));
            }
        }
    } catch (IllegalBlockSizeException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    } catch (BadPaddingException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    } catch (InvalidKeyException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    } catch (NoSuchPaddingException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error while checking credentials file",
                ex.getMessage());
    }
    return token;
}