Search in sources :

Example 46 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.

the class AlgorithmParameters method init.

/**
 * Initializes this parameter object using the parameters
 * specified in {@code paramSpec}.
 *
 * @param paramSpec the parameter specification.
 *
 * @exception InvalidParameterSpecException if the given parameter
 * specification is inappropriate for the initialization of this parameter
 * object, or if this parameter object has already been initialized.
 */
public final void init(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (this.initialized)
        throw new InvalidParameterSpecException("already initialized");
    paramSpi.engineInit(paramSpec);
    this.initialized = true;
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException)

Example 47 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project light-4j by networknt.

the class AESEncryptor method encrypt.

/**
 * Encrypt given input string
 *
 * @param input
 * @return
 * @throws RuntimeException
 */
public String encrypt(String input) {
    try {
        byte[] inputBytes = input.getBytes(STRING_ENCODING);
        // CBC = Cipher Block chaining
        // PKCS5Padding Indicates that the keys are padded
        cipher.init(Cipher.ENCRYPT_MODE, secret);
        AlgorithmParameters params = cipher.getParameters();
        byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
        byte[] ciphertext = cipher.doFinal(inputBytes);
        byte[] out = new byte[iv.length + ciphertext.length];
        System.arraycopy(iv, 0, out, 0, iv.length);
        System.arraycopy(ciphertext, 0, out, iv.length, ciphertext.length);
        return CRYPT_PREFIX + ":" + base64Encoder.encode(out);
    } catch (IllegalBlockSizeException e) {
        throw new RuntimeException("Unable to encrypt", e);
    } catch (BadPaddingException e) {
        throw new RuntimeException("Unable to encrypt", e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException("Unable to encrypt", e);
    } catch (InvalidParameterSpecException e) {
        throw new RuntimeException("Unable to encrypt", e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Unable to encrypt", e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) InvalidKeyException(java.security.InvalidKeyException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 48 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException02.

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

Example 49 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException03.

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

Example 50 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException01.

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

Aggregations

InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)57 AlgorithmParameters (java.security.AlgorithmParameters)22 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 IvParameterSpec (javax.crypto.spec.IvParameterSpec)16 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)11 InvalidKeyException (java.security.InvalidKeyException)8 BadPaddingException (javax.crypto.BadPaddingException)7 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)7 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)7 DSAParameterSpec (java.security.spec.DSAParameterSpec)6 Cipher (javax.crypto.Cipher)6 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)6 Nullable (android.annotation.Nullable)5 ProviderException (java.security.ProviderException)5 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)5 BigInteger (java.math.BigInteger)4 DSAParams (java.security.interfaces.DSAParams)4 SecretKeySpec (javax.crypto.spec.SecretKeySpec)4 IOException (java.io.IOException)3