private static byte[] decrypt(byte[] content, String password) { try { byte[] keyStr = getKey(password); SecretKeySpec key = new SecretKeySpec(keyStr, "AES"); Cipher cipher = Cipher.getInstance(algorithmStr);//algorithmStr cipher.init(Cipher.DECRYPT_MODE, key);// ʼ byte[] result = cipher.doFinal(content); return result; // } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } return null; }
Cipher cipher = Cipher.getInstance(algName); if (algParameters == null) { cipher.init(Cipher.DECRYPT_MODE, decryptKey); } else { cipher.init(Cipher.DECRYPT_MODE, decryptKey, algParameters); byte[] decryptedData = cipher.doFinal(encryptedData); throw new NoSuchAlgorithmException(e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new NoSuchAlgorithmException(e.getMessage()); } catch (IllegalStateException e) { throw new InvalidKeyException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
static int get(String padding) throws NoSuchPaddingException { try { return Padding.valueOf(padding).ordinal(); } catch (Exception e) { throw new NoSuchPaddingException("Doesn't support padding: " + padding); } } }
NoSuchAlgorithmException, InvalidKeyException { if (key == null) { throw new InvalidKeyException("key == null"); Cipher cipher = Cipher.getInstance(sealAlg); if ((paramsAlg != null) && (paramsAlg.length() != 0)) { AlgorithmParameters params = AlgorithmParameters.getInstance(paramsAlg); params.init(encodedParams); cipher.init(Cipher.DECRYPT_MODE, key, params); } else { cipher.init(Cipher.DECRYPT_MODE, key); byte[] serialized = cipher.doFinal(encryptedContent); throw new NoSuchAlgorithmException(e.toString()); } catch (InvalidAlgorithmParameterException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (IllegalBlockSizeException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (BadPaddingException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (IllegalStateException e) {
Cipher c = Cipher.getInstance("AES"); c.init(Cipher.ENCRYPT_MODE, deskey); byte[] src = str.getBytes(); byte[] cipherByte = c.doFinal(src); LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (UnsupportedEncodingException e) { LOGGER.error("Bsae64加密异常:" + e.getMessage()); throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage()); } catch (NoSuchPaddingException e) { LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (InvalidKeyException e) { LOGGER.error("初始化Cipher对象异常:" + e.getMessage()); throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage()); } catch (IllegalBlockSizeException e) { LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage()); } catch (BadPaddingException e) { LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage());
/** * Initialize the ciphers used for encryption and decryption. The ciphers * define the algorithms to be used. They are initialized with the * appropriate key to be used in the encryption or decryption operation. */ protected void initDecryptCipher() throws CryptoException { // Create and initialize decryption cipher try { decryptCipher = Cipher.getInstance( cipherAlgorithm); decryptCipher.init( Cipher.DECRYPT_MODE, decryptKey, iv ); } catch ( NoSuchAlgorithmException e ) { throw new CryptoException(CorePlugin.Event.TEIID10009, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10009, cipherAlgorithm )); } catch ( NoSuchPaddingException e ) { throw new CryptoException(CorePlugin.Event.TEIID10010, CorePlugin.Util.gs(CorePlugin.Event.TEIID10010, cipherAlgorithm, e.getClass().getName(), e.getMessage() )); } catch ( InvalidKeyException e ) { throw new CryptoException(CorePlugin.Event.TEIID10011, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10011, e.getClass().getName(), e.getMessage()) ); } catch (InvalidAlgorithmParameterException e) { throw new CryptoException(CorePlugin.Event.TEIID10009, e, CorePlugin.Util.gs(CorePlugin.Event.TEIID10009, cipherAlgorithm )); } }
private Cipher getCipher(byte[] key) throws SVNException { try { final Cipher ecipher = Cipher.getInstance("DES/ECB/NoPadding"); key = setupKey(key); ecipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES")); return ecipher; } catch (NoSuchAlgorithmException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "DES encryption is not available: {0}", e.getLocalizedMessage()); SVNErrorManager.error(err, SVNLogType.NETWORK); } catch (InvalidKeyException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Invalid key for DES encryption: {0}", e.getLocalizedMessage()); SVNErrorManager.error(err, SVNLogType.NETWORK); } catch (NoSuchPaddingException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "NoPadding option for DES is not available: {0}", e.getLocalizedMessage()); SVNErrorManager.error(err, SVNLogType.NETWORK); } return null; }
if (provider == null) c = Cipher.getInstance("AES/CCM/NoPadding"); c = Cipher.getInstance("AES/CCM/NoPadding", provider); c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, "AES")); byte[] encOut = c.doFinal(storeData.getEncoded()); throw new NoSuchAlgorithmException(e.toString()); throw new IOException(e.toString()); throw new IOException(e.toString()); throw new IOException(e.toString());
Cipher cipher; try { cipher = Cipher.getInstance(ePKInfo.getAlgName()); } catch (NoSuchPaddingException npex) { throw new NoSuchAlgorithmException(npex.getMessage(), npex); cipher.init(Cipher.DECRYPT_MODE, pbeKey, algParams); } catch (NoSuchAlgorithmException ex) { error = new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.", ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex); return null;
e.printStackTrace(); try { cipher = Cipher.getInstance(algorithmStr); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace();
private static Cipher aesCipher() throws BraintreeEncryptionException { try { return Cipher.getInstance(TRANSFORMATION); } catch (NoSuchAlgorithmException e) { throw new BraintreeEncryptionException("No Such Algorithm: " + e.getMessage()); } catch (NoSuchPaddingException e) { throw new BraintreeEncryptionException("No Such Padding: " + e.getMessage()); } } }
private AesCmac(Key key, int length) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException { if (length > BLOCK_SIZE) { throw new NoSuchAlgorithmException("AES CMAC maximum length is " + BLOCK_SIZE); } try { macLength = length; aesCipher = Cipher.getInstance("AES_128/CBC/NoPadding"); buffer = new byte[BLOCK_SIZE]; } catch (NoSuchPaddingException nspe) { nspe.printStackTrace(); } init(key); }
byte[] encOut = c.doFinal(storeData.getEncoded()); AlgorithmParameters algorithmParameters = c.getParameters(); byte[] encOut = c.doFinal(storeData.getEncoded()); PBES2Parameters pbeParams = new PBES2Parameters(pbkdAlgId, new EncryptionScheme(NISTObjectIdentifiers.id_aes256_wrap_pad)); throw new NoSuchAlgorithmException(e.toString()); throw new IOException(e.toString()); throw new IOException(e.toString()); throw new IOException(e.toString());
return __verifyNonRepSignature(expectedDigestValue, signatureValue, certificate); } catch (final InvalidKeyException ikex) { LOGGER.warn("invalid key: " + ikex.getMessage(), ikex); return false; } catch (final NoSuchAlgorithmException nsaex) { LOGGER.warn("no such algo: " + nsaex.getMessage(), nsaex); return false; } catch (final NoSuchPaddingException nspex) { LOGGER.warn("no such padding: " + nspex.getMessage(), nspex); return false; } catch (final BadPaddingException bpex) { LOGGER.warn("bad padding: " + bpex.getMessage(), bpex); return false; } catch (final IOException ioex) { return false; } catch (final IllegalBlockSizeException ibex) { LOGGER.warn("illegal block size: " + ibex.getMessage(), ibex); return false;
@Override public byte[] getSignedData(String alias, byte[] data) throws RemoteException { try { return SimpleSigner.signData(data); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } // Something failed, return null return null; }
/** * Returns an inputstream that will decrypt the bytes coming in through the specified input using the given key * @param theStream the stream to read encrypted data from * @param theKey the key to use for decryption * @return an input stream that will decrypt the data * @throws IOException if the stream cannot be read from, or if there is an error while decrypting */ public static InputStream decrypt(InputStream theStream, SecretKey theKey) throws IOException { try { return new CipherInputStream(theStream, createDecryptCipher(theKey)); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e.getMessage()); } catch (InvalidKeyException e) { throw new IOException(e.getMessage()); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage()); } catch (NoSuchPaddingException e) { throw new IOException(e.getMessage()); } }
public String encrypt(String input) throws PubNubException { try { initCiphers(); AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes); SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = null; cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec); return new String(Base64.encode(cipher.doFinal(input.getBytes("UTF-8")), 0), Charset.forName("UTF-8")); } catch (NoSuchAlgorithmException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (NoSuchPaddingException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (InvalidKeyException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (InvalidAlgorithmParameterException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (UnsupportedEncodingException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (IllegalBlockSizeException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } catch (BadPaddingException e) { throw PubNubException.builder().errormsg(e.toString()).build(); } }
public CipherSpi( OAEPParameterSpec pSpec) { try { initFromSpec(pSpec); } catch (NoSuchPaddingException e) { throw new IllegalArgumentException(e.getMessage()); } }
throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e); } catch (NoSuchPaddingException e) { throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e); } catch (NoSuchAlgorithmException e) { throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e); } catch (IllegalBlockSizeException e) { throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e); } catch (BadPaddingException e) { throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e); } catch (InvalidAlgorithmParameterException e) { throw new DPKException("Failed to encrypt DPK. Cause: " + e.getLocalizedMessage(), e);
Cipher cipher = Cipher.getInstance(sealAlg, provider); if ((paramsAlg != null) && (paramsAlg.length() != 0)) { AlgorithmParameters params = AlgorithmParameters.getInstance(paramsAlg); params.init(encodedParams); cipher.init(Cipher.DECRYPT_MODE, key, params); } else { cipher.init(Cipher.DECRYPT_MODE, key); byte[] serialized = cipher.doFinal(encryptedContent); throw new NoSuchAlgorithmException(e.toString()); } catch (InvalidAlgorithmParameterException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (IllegalBlockSizeException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (BadPaddingException e) { throw new NoSuchAlgorithmException(e.toString()); } catch (IllegalStateException e) {