Search in sources :

Example 81 with InvalidKeySpecException

use of java.security.spec.InvalidKeySpecException in project robovm by robovm.

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException03.

/**
     * Test for <code>InvalidKeySpecException(String)</code> constructor
     * Assertion: constructs InvalidKeySpecException when <code>msg</code> is
     * null
     */
public void testInvalidKeySpecException03() {
    String msg = null;
    InvalidKeySpecException tE = new InvalidKeySpecException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 82 with InvalidKeySpecException

use of java.security.spec.InvalidKeySpecException in project robovm by robovm.

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException09.

/**
     * Test for <code>InvalidKeySpecException(String, Throwable)</code>
     * constructor Assertion: constructs InvalidKeySpecException when
     * <code>cause</code> is not null <code>msg</code> is not null
     */
public void testInvalidKeySpecException09() {
    InvalidKeySpecException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new InvalidKeySpecException(msgs[i], tCause);
        String getM = tE.getMessage();
        String toS = tCause.toString();
        if (msgs[i].length() > 0) {
            assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
            if (!getM.equals(msgs[i])) {
                assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
            }
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
    }
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 83 with InvalidKeySpecException

use of java.security.spec.InvalidKeySpecException in project robovm by robovm.

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException04.

/**
     * Test for <code>InvalidKeySpecException(Throwable)</code> constructor
     * Assertion: constructs InvalidKeySpecException when <code>cause</code>
     * is null
     */
public void testInvalidKeySpecException04() {
    Throwable cause = null;
    InvalidKeySpecException tE = new InvalidKeySpecException(cause);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 84 with InvalidKeySpecException

use of java.security.spec.InvalidKeySpecException in project robovm by robovm.

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException06.

/**
     * Test for <code>InvalidKeySpecException(String, Throwable)</code>
     * constructor Assertion: constructs InvalidKeySpecException when
     * <code>cause</code> is null <code>msg</code> is null
     */
public void testInvalidKeySpecException06() {
    InvalidKeySpecException tE = new InvalidKeySpecException(null, null);
    assertNull("getMessage() must return null", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 85 with InvalidKeySpecException

use of java.security.spec.InvalidKeySpecException in project robovm by robovm.

the class mySecretKeyFactory method testSecretKeyFactory10.

/**
     * Test for <code>generateSecret(KeySpec keySpec)</code> and
     * <code>getKeySpec(SecretKey key, Class keySpec)
     * methods
     * Assertion:
     * throw InvalidKeySpecException if parameter is inappropriate
     */
public void testSecretKeyFactory10() throws InvalidKeyException, InvalidKeySpecException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    byte[] bb = new byte[24];
    KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec) new DESKeySpec(bb) : (KeySpec) new DESedeKeySpec(bb));
    KeySpec rks = null;
    SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm);
    SecretKey secKey = null;
    SecretKeyFactory[] skF = createSKFac();
    assertNotNull("SecretKeyFactory object were not created", skF);
    for (int i = 0; i < skF.length; i++) {
        try {
            skF[i].generateSecret(null);
            fail("generateSecret(null): InvalidKeySpecException must be thrown");
        } catch (InvalidKeySpecException e) {
        }
        secKey = skF[i].generateSecret(ks);
        try {
            skF[i].getKeySpec(null, null);
            fail("getKeySpec(null,null): InvalidKeySpecException must be thrown");
        } catch (InvalidKeySpecException e) {
        }
        try {
            skF[i].getKeySpec(null, ks.getClass());
            fail("getKeySpec(null, Class): InvalidKeySpecException must be thrown");
        } catch (InvalidKeySpecException e) {
        }
        try {
            skF[i].getKeySpec(secKey, null);
            fail("getKeySpec(secKey, null): NullPointerException or InvalidKeySpecException must be thrown");
        } catch (InvalidKeySpecException e) {
        // Expected
        } catch (NullPointerException e) {
        // Expected
        }
        try {
            Class c;
            if (defaultAlgorithm.equals(defaultAlgorithm2)) {
                c = DESedeKeySpec.class;
            } else {
                c = DESKeySpec.class;
            }
            skF[i].getKeySpec(secKeySpec, c);
            fail("getKeySpec(secKey, Class): InvalidKeySpecException must be thrown");
        } catch (InvalidKeySpecException e) {
        }
        rks = skF[i].getKeySpec(secKeySpec, ks.getClass());
        if (defaultAlgorithm.equals(defaultAlgorithm1)) {
            assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESedeKeySpec);
        } else {
            assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESKeySpec);
        }
        rks = skF[i].getKeySpec(secKey, ks.getClass());
        if (defaultAlgorithm.equals(defaultAlgorithm1)) {
            assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESedeKeySpec);
        } else {
            assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESKeySpec);
        }
    }
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) DESKeySpec(javax.crypto.spec.DESKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) DESedeKeySpec(javax.crypto.spec.DESedeKeySpec) KeySpec(java.security.spec.KeySpec) DESedeKeySpec(javax.crypto.spec.DESedeKeySpec) DESKeySpec(javax.crypto.spec.DESKeySpec) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SecretKeyFactory(javax.crypto.SecretKeyFactory)

Aggregations

InvalidKeySpecException (java.security.spec.InvalidKeySpecException)237 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)147 KeyFactory (java.security.KeyFactory)99 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)93 InvalidKeyException (java.security.InvalidKeyException)62 PublicKey (java.security.PublicKey)57 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)56 IOException (java.io.IOException)51 PrivateKey (java.security.PrivateKey)40 SecretKeyFactory (javax.crypto.SecretKeyFactory)30 PBEKeySpec (javax.crypto.spec.PBEKeySpec)27 SignatureException (java.security.SignatureException)22 UnsupportedEncodingException (java.io.UnsupportedEncodingException)21 KeySpec (java.security.spec.KeySpec)19 BadPaddingException (javax.crypto.BadPaddingException)19 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)19 BigInteger (java.math.BigInteger)17 SecretKeySpec (javax.crypto.spec.SecretKeySpec)16 NoSuchProviderException (java.security.NoSuchProviderException)15 RSAPublicKey (java.security.interfaces.RSAPublicKey)15