use of javax.crypto.NoSuchPaddingException in project jgnash by ccavanaugh.
the class EncryptionManager method encrypt.
/**
* Encrypts the supplied string.
*
* @param plain String to encrypt
* @return the encrypted string
*/
public String encrypt(final String plain) {
try {
final Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, key);
return Base64.getEncoder().encodeToString(cipher.doFinal(plain.getBytes(StandardCharsets.UTF_8)));
} catch (final InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
LogUtil.logSevere(EncryptionManager.class, e);
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project Conversations by siacs.
the class XmppAxolotlMessage method encrypt.
void encrypt(final String plaintext) throws CryptoFailedException {
try {
SecretKey secretKey = new SecretKeySpec(innerKey, KEYTYPE);
IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
this.ciphertext = cipher.doFinal(Config.OMEMO_PADDING ? getPaddedBytes(plaintext) : plaintext.getBytes());
if (Config.PUT_AUTH_TAG_INTO_KEY && this.ciphertext != null) {
this.authtagPlusInnerKey = new byte[16 + 16];
byte[] ciphertext = new byte[this.ciphertext.length - 16];
System.arraycopy(this.ciphertext, 0, ciphertext, 0, ciphertext.length);
System.arraycopy(this.ciphertext, ciphertext.length, authtagPlusInnerKey, 16, 16);
System.arraycopy(this.innerKey, 0, authtagPlusInnerKey, 0, this.innerKey.length);
this.ciphertext = ciphertext;
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
throw new CryptoFailedException(e);
}
}
use of javax.crypto.NoSuchPaddingException in project j2objc by google.
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 j2objc by google.
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 ExoPlayer by google.
the class Aes128DataSource method open.
@Override
public final long open(DataSpec dataSpec) throws IOException {
Cipher cipher;
try {
cipher = getCipherInstance();
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException(e);
}
Key cipherKey = new SecretKeySpec(encryptionKey, "AES");
AlgorithmParameterSpec cipherIV = new IvParameterSpec(encryptionIv);
try {
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherIV);
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
DataSourceInputStream inputStream = new DataSourceInputStream(upstream, dataSpec);
cipherInputStream = new CipherInputStream(inputStream, cipher);
inputStream.open();
return C.LENGTH_UNSET;
}
Aggregations