Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;

import javax.crypto.ShortBufferException;

public class Main {
    /**
     * Invokes the Cipher to perform encryption or decryption (depending on the initialized mode).
     */
    public static byte[] doFinal(Cipher cipher, byte[] input) {
        try {
            return cipher.doFinal(input);
        } catch (IllegalBlockSizeException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);
        } catch (BadPaddingException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e);
        }
    }

    /**
     * Invokes the Cipher to perform encryption or decryption (depending on the
     * initialized mode).
     */
    public static byte[] doFinal(Cipher cipher, byte[] input, int inputOffSet, int inputLen) {
        try {
            return cipher.doFinal(input, inputOffSet, inputLen);
        } catch (IllegalBlockSizeException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);
        } catch (BadPaddingException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e);
        }
    }

    /**
     * Invokes the Cipher to perform encryption or decryption (depending on the
     * initialized mode).
     */
    public static int doFinal(Cipher cipher, byte[] input, int inputOffSet, int inputLen, byte[] ouput,
            int outputOffSet) {
        try {
            return cipher.doFinal(input, inputOffSet, inputLen, ouput, outputOffSet);
        } catch (IllegalBlockSizeException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);
        } catch (BadPaddingException e) {
            throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e);
        } catch (ShortBufferException e) {
            throw new IllegalStateException("Short Buffer Exception", e);
        }
    }
}