use of javax.crypto.NoSuchPaddingException in project HL4A by HL4A.
the class AES method encrypt.
private byte[] encrypt(String cmp, SecretKey sk, IvParameterSpec IV, byte[] msg) {
try {
Cipher c = Cipher.getInstance(cmp);
c.init(Cipher.ENCRYPT_MODE, sk, IV);
return c.doFinal(msg);
} catch (NoSuchAlgorithmException nsae) {
Log.e("AESdemo", "no cipher getinstance support for " + cmp);
} catch (NoSuchPaddingException nspe) {
Log.e("AESdemo", "no cipher getinstance support for padding " + cmp);
} catch (InvalidKeyException e) {
Log.e("AESdemo", "invalid key exception");
} catch (InvalidAlgorithmParameterException e) {
Log.e("AESdemo", "invalid algorithm parameter exception");
} catch (IllegalBlockSizeException e) {
Log.e("AESdemo", "illegal block size exception");
} catch (BadPaddingException e) {
Log.e("AESdemo", "bad padding exception");
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project spring-security by spring-projects.
the class CryptoAssumptions method assumeAes256.
private static void assumeAes256(CipherAlgorithm cipherAlgorithm) {
boolean aes256Available = false;
try {
Cipher.getInstance(cipherAlgorithm.toString());
aes256Available = Cipher.getMaxAllowedKeyLength("AES") >= 256;
} catch (NoSuchAlgorithmException ex) {
throw new TestAbortedException(cipherAlgorithm + " not available, skipping test", ex);
} catch (NoSuchPaddingException ex) {
throw new TestAbortedException(cipherAlgorithm + " padding not available, skipping test", ex);
}
Assumptions.assumeTrue(aes256Available, "AES key length of 256 not allowed, skipping test");
}
use of javax.crypto.NoSuchPaddingException in project orientdb by orientechnologies.
the class OSymmetricKey method encrypt.
/**
* This method encrypts an array of bytes.
*
* @param transform The cipher transformation to use.
* @param bytes The array of bytes to be encrypted.
*
* @return The encrypted bytes as a Base64-encoded JSON document or null if unsuccessful.
*/
public String encrypt(final String transform, final byte[] bytes) {
String encodedJSON = null;
if (secretKey == null)
throw new OSecurityException("OSymmetricKey.encrypt() SecretKey is null");
if (transform == null)
throw new OSecurityException("OSymmetricKey.encrypt() Cannot determine cipher transformation");
try {
// Throws NoSuchAlgorithmException and NoSuchPaddingException.
Cipher cipher = Cipher.getInstance(transform);
// If the cipher transformation requires an initialization vector then init() will create a random one.
// (Use cipher.getIV() to retrieve the IV, if it exists.)
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// If the cipher does not use an IV, this will be null.
byte[] initVector = cipher.getIV();
// byte[] initVector = encCipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
byte[] encrypted = cipher.doFinal(bytes);
encodedJSON = encodeJSON(encrypted, initVector);
} catch (Exception ex) {
throw new OSecurityException("OSymmetricKey.encrypt() Exception: " + ex.getMessage());
}
return encodedJSON;
}
use of javax.crypto.NoSuchPaddingException in project LuaViewSDK by alibaba.
the class DecryptUtil method aes.
/**
* 使用aes256进行解密
*
* @param encrypted
* @return
*/
public static byte[] aes(final byte[] keys, final byte[] encrypted) {
try {
// get cipher
Cipher cipher = AppCache.getCache(CACHE_PUBLIC_KEY).get(Constants.PUBLIC_KEY_PATH_CIPHER);
if (cipher == null) {
final SecretKeySpec skeySpec = new SecretKeySpec(keys, ALGORITHM_AES);
final IvParameterSpec ivParameterSpec = new IvParameterSpec(cIv);
cipher = Cipher.getInstance(ALGORITHM_AES);
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec);
// cache cipher
AppCache.getCache(CACHE_PUBLIC_KEY).put(Constants.PUBLIC_KEY_PATH_CIPHER, cipher);
}
return cipher.doFinal(encrypted);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project jgnash by ccavanaugh.
the class EncryptionManager method decrypt.
/**
* Decrypts the supplied string.
*
* @param encrypted String to decrypt
* @return The decrypted string of {@code DECRYPTION_ERROR_TAG} if decryption fails
* @see #DECRYPTION_ERROR_TAG
*/
public String decrypt(final String encrypted) {
try {
final Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
return new String(cipher.doFinal(Base64.getDecoder().decode(encrypted)), StandardCharsets.UTF_8);
} catch (final InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
logger.log(Level.SEVERE, "Invalid password");
return DECRYPTION_ERROR_TAG;
}
}
Aggregations