use of javax.crypto.NoSuchPaddingException in project sling by apache.
the class TopologyRequestValidator method encodeMessage.
/**
* Encodes a request returning the encoded body
*
* @param body
* @return the encoded body.
* @throws IOException
*/
public String encodeMessage(String body) throws IOException {
checkActive();
if (encryptionEnabled) {
try {
JsonObjectBuilder json = Json.createObjectBuilder();
JsonArrayBuilder array = Json.createArrayBuilder();
for (String value : encrypt(body)) {
array.add(value);
}
json.add("payload", array);
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write(json.build()).close();
return writer.toString();
} catch (InvalidKeyException e) {
e.printStackTrace();
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (IllegalBlockSizeException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (BadPaddingException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (UnsupportedEncodingException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (NoSuchPaddingException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (JsonException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (InvalidKeySpecException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
} catch (InvalidParameterSpecException e) {
throw new IOException("Unable to Encrypt Message " + e.getMessage());
}
}
return body;
}
use of javax.crypto.NoSuchPaddingException in project robovm by robovm.
the class NoSuchPaddingExceptionTest method testNoSuchPaddingException01.
/**
* Test for <code>NoSuchPaddingException()</code> constructor Assertion:
* constructs NoSuchPaddingException with no detail message
*/
public void testNoSuchPaddingException01() {
NoSuchPaddingException tE = new NoSuchPaddingException();
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of javax.crypto.NoSuchPaddingException in project robovm by robovm.
the class NoSuchPaddingExceptionTest method testNoSuchPaddingException03.
/**
* Test for <code>NoSuchPaddingException(String)</code> constructor
* Assertion: constructs NoSuchPaddingException when <code>msg</code> is
* null
*/
public void testNoSuchPaddingException03() {
String msg = null;
NoSuchPaddingException tE = new NoSuchPaddingException(msg);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of javax.crypto.NoSuchPaddingException in project robovm by robovm.
the class NoSuchPaddingExceptionTest method testNoSuchPaddingException02.
/**
* Test for <code>NoSuchPaddingException(String)</code> constructor
* Assertion: constructs NoSuchPaddingException with detail message msg.
* Parameter <code>msg</code> is not null.
*/
public void testNoSuchPaddingException02() {
NoSuchPaddingException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new NoSuchPaddingException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of javax.crypto.NoSuchPaddingException in project robovm by robovm.
the class AlgorithmParameterSymmetricHelper method test.
@Override
public void test(AlgorithmParameters parameters) {
KeyGenerator generator = null;
try {
generator = KeyGenerator.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
}
generator.init(keySize);
Key key = generator.generateKey();
Cipher cipher = null;
try {
String transformation = algorithmName;
if (blockmode != null) {
transformation += "/" + blockmode;
}
cipher = Cipher.getInstance(transformation);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
} catch (NoSuchPaddingException e) {
Assert.fail(e.getMessage());
}
try {
cipher.init(Cipher.ENCRYPT_MODE, key, parameters);
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
Assert.fail(e.getMessage());
}
byte[] bs = null;
try {
bs = cipher.doFinal(plainData.getBytes());
} catch (IllegalBlockSizeException e) {
Assert.fail(e.getMessage());
} catch (BadPaddingException e) {
Assert.fail(e.getMessage());
}
try {
cipher.init(Cipher.DECRYPT_MODE, key, parameters);
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
Assert.fail(e.getMessage());
}
byte[] decrypted = null;
try {
decrypted = cipher.doFinal(bs);
} catch (IllegalBlockSizeException e) {
Assert.fail(e.getMessage());
} catch (BadPaddingException e) {
Assert.fail(e.getMessage());
}
Assert.assertTrue(Arrays.equals(plainData.getBytes(), decrypted));
}
Aggregations