Search in sources :

Example 76 with InvalidKeySpecException

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

the class SignatureTest method testSign_SHA1withRSA_Key_EmptyKey_Failure.

public void testSign_SHA1withRSA_Key_EmptyKey_Failure() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(null, null);
    // Failing on this key early is okay.
    final PrivateKey privKey;
    try {
        privKey = kf.generatePrivate(keySpec);
    } catch (NullPointerException e) {
        return;
    } catch (InvalidKeySpecException e) {
        return;
    }
    Signature sig = Signature.getInstance("SHA1withRSA");
    try {
        sig.initSign(privKey);
        fail("Should throw error when key is empty");
    } catch (InvalidKeyException expected) {
    }
}
Also used : PrivateKey(java.security.PrivateKey) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) Signature(java.security.Signature) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidKeyException(java.security.InvalidKeyException) KeyFactory(java.security.KeyFactory)

Example 77 with InvalidKeySpecException

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

the class EncryptedPrivateKeyInfoTest method testGetKeySpecCipher01.

public final void testGetKeySpecCipher01() {
    boolean performed = false;
    for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
        try {
            EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.algName0[i][0], EncryptedPrivateKeyInfoData.encryptedData);
            try {
                // check that method under test throws NPE
                epki.getKeySpec((Cipher) null);
                fail(getName() + "NullPointerException has not been thrown");
            } catch (NullPointerException ok) {
            } catch (InvalidKeySpecException e) {
                fail(getName() + "Unexpected exception: " + e);
            }
            performed = true;
        } catch (NoSuchAlgorithmException allowedFailure) {
        }
    }
    assertTrue("Test not performed", performed);
}
Also used : EncryptedPrivateKeyInfo(javax.crypto.EncryptedPrivateKeyInfo) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 78 with InvalidKeySpecException

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

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException01.

/**
     * Test for <code>InvalidKeySpecException()</code> constructor Assertion:
     * constructs InvalidKeySpecException with no detail message
     */
public void testInvalidKeySpecException01() {
    InvalidKeySpecException tE = new InvalidKeySpecException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 79 with InvalidKeySpecException

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

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException05.

/**
     * Test for <code>InvalidKeySpecException(Throwable)</code> constructor
     * Assertion: constructs InvalidKeySpecException when <code>cause</code>
     * is not null
     */
public void testInvalidKeySpecException05() {
    InvalidKeySpecException tE = new InvalidKeySpecException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        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 80 with InvalidKeySpecException

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

the class InvalidKeySpecExceptionTest method testInvalidKeySpecException07.

/**
     * Test for <code>InvalidKeySpecException(String, Throwable)</code>
     * constructor Assertion: constructs InvalidKeySpecException when
     * <code>cause</code> is null <code>msg</code> is not null
     */
public void testInvalidKeySpecException07() {
    InvalidKeySpecException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new InvalidKeySpecException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

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