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;
}
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);
}
}
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());
}
}
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());
}
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());
}
Aggregations