Search in sources :

Example 46 with ShortBufferException

use of javax.crypto.ShortBufferException in project robovm by robovm.

the class ExemptionMechanismTest method test_genExemptionBlob$B.

public void test_genExemptionBlob$B() throws InvalidKeyException, ExemptionMechanismException, ShortBufferException {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    try {
        em.genExemptionBlob(new byte[10]);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertEquals(5, (em.genExemptionBlob(new byte[10])));
    try {
        em.genExemptionBlob(new byte[2]);
        fail("ShortBufferException expected");
    } catch (ShortBufferException e) {
    //failed
    }
    byte[] b = new byte[] { 0, 0, 0, 33, 0 };
    try {
        em.genExemptionBlob(b);
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //failed
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) ShortBufferException(javax.crypto.ShortBufferException) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 47 with ShortBufferException

use of javax.crypto.ShortBufferException in project platform_frameworks_base by android.

the class AndroidKeyStoreCipherSpiBase method engineUpdate.

@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
    if (input == null) {
        throw new NullPointerException("input == null");
    }
    if (output == null) {
        throw new NullPointerException("output == null");
    }
    int inputSize = input.remaining();
    byte[] outputArray;
    if (input.hasArray()) {
        outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
        input.position(input.position() + inputSize);
    } else {
        byte[] inputArray = new byte[inputSize];
        input.get(inputArray);
        outputArray = engineUpdate(inputArray, 0, inputSize);
    }
    int outputSize = (outputArray != null) ? outputArray.length : 0;
    if (outputSize > 0) {
        int outputBufferAvailable = output.remaining();
        try {
            output.put(outputArray);
        } catch (BufferOverflowException e) {
            throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
        }
    }
    return outputSize;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 48 with ShortBufferException

use of javax.crypto.ShortBufferException in project android_frameworks_base by DirtyUnicorns.

the class AndroidKeyStoreCipherSpiBase method engineUpdate.

@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
    if (input == null) {
        throw new NullPointerException("input == null");
    }
    if (output == null) {
        throw new NullPointerException("output == null");
    }
    int inputSize = input.remaining();
    byte[] outputArray;
    if (input.hasArray()) {
        outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
        input.position(input.position() + inputSize);
    } else {
        byte[] inputArray = new byte[inputSize];
        input.get(inputArray);
        outputArray = engineUpdate(inputArray, 0, inputSize);
    }
    int outputSize = (outputArray != null) ? outputArray.length : 0;
    if (outputSize > 0) {
        int outputBufferAvailable = output.remaining();
        try {
            output.put(outputArray);
        } catch (BufferOverflowException e) {
            throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
        }
    }
    return outputSize;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 49 with ShortBufferException

use of javax.crypto.ShortBufferException in project android_frameworks_base by AOSPA.

the class AndroidKeyStoreCipherSpiBase method engineUpdate.

@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
    if (input == null) {
        throw new NullPointerException("input == null");
    }
    if (output == null) {
        throw new NullPointerException("output == null");
    }
    int inputSize = input.remaining();
    byte[] outputArray;
    if (input.hasArray()) {
        outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
        input.position(input.position() + inputSize);
    } else {
        byte[] inputArray = new byte[inputSize];
        input.get(inputArray);
        outputArray = engineUpdate(inputArray, 0, inputSize);
    }
    int outputSize = (outputArray != null) ? outputArray.length : 0;
    if (outputSize > 0) {
        int outputBufferAvailable = output.remaining();
        try {
            output.put(outputArray);
        } catch (BufferOverflowException e) {
            throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
        }
    }
    return outputSize;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 50 with ShortBufferException

use of javax.crypto.ShortBufferException in project robovm by robovm.

the class CipherTest method testUpdatebyteArrayintintbyteArrayint.

/*
     * Class under test for int update(byte[], int, int, byte[], int)
     */
public void testUpdatebyteArrayintintbyteArrayint() throws Exception {
    byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    byte[] b1 = new byte[6];
    Cipher c = Cipher.getInstance("DESede");
    try {
        c.update(b, 0, 10, b1, 5);
        fail();
    } catch (IllegalStateException expected) {
    }
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
    try {
        c.update(b, 0, 10, b1, 5);
        fail();
    } catch (ShortBufferException expected) {
    }
    b1 = new byte[30];
    c.update(b, 0, 10, b1, 5);
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher)

Aggregations

ShortBufferException (javax.crypto.ShortBufferException)69 BadPaddingException (javax.crypto.BadPaddingException)24 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)24 Cipher (javax.crypto.Cipher)22 InvalidKeyException (java.security.InvalidKeyException)17 ByteBuffer (java.nio.ByteBuffer)15 IvParameterSpec (javax.crypto.spec.IvParameterSpec)15 SecretKeySpec (javax.crypto.spec.SecretKeySpec)13 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)12 BufferOverflowException (java.nio.BufferOverflowException)10 IOException (java.io.IOException)9 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)9 MyCipher (org.apache.harmony.crypto.tests.support.MyCipher)7 SecretKey (javax.crypto.SecretKey)6 NoSuchProviderException (java.security.NoSuchProviderException)5 Random (java.util.Random)5 KeyGenerator (javax.crypto.KeyGenerator)5 MessageDigest (java.security.MessageDigest)4