Search in sources :

Example 91 with NoSuchPaddingException

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;
}
Also used : NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException)

Example 92 with NoSuchPaddingException

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);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) NoSuchProviderException(java.security.NoSuchProviderException)

Example 93 with NoSuchPaddingException

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());
}
Also used : NoSuchPaddingException(javax.crypto.NoSuchPaddingException)

Example 94 with NoSuchPaddingException

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());
    }
}
Also used : NoSuchPaddingException(javax.crypto.NoSuchPaddingException)

Example 95 with NoSuchPaddingException

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;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CipherInputStream(javax.crypto.CipherInputStream) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) Key(java.security.Key) DataSourceInputStream(com.google.android.exoplayer2.upstream.DataSourceInputStream)

Aggregations

NoSuchPaddingException (javax.crypto.NoSuchPaddingException)259 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)237 InvalidKeyException (java.security.InvalidKeyException)216 Cipher (javax.crypto.Cipher)187 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)181 BadPaddingException (javax.crypto.BadPaddingException)180 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)119 SecretKeySpec (javax.crypto.spec.SecretKeySpec)91 IOException (java.io.IOException)83 IvParameterSpec (javax.crypto.spec.IvParameterSpec)66 SecretKey (javax.crypto.SecretKey)45 KeyStoreException (java.security.KeyStoreException)40 CertificateException (java.security.cert.CertificateException)40 UnrecoverableKeyException (java.security.UnrecoverableKeyException)35 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 NoSuchProviderException (java.security.NoSuchProviderException)27 GCMParameterSpec (javax.crypto.spec.GCMParameterSpec)18 FileNotFoundException (java.io.FileNotFoundException)16 SecureRandom (java.security.SecureRandom)16