List of usage examples for javax.crypto Cipher DECRYPT_MODE
int DECRYPT_MODE
To view the source code for javax.crypto Cipher DECRYPT_MODE.
Click Source Link
From source file:com.AES256Util.java
public String aesDecode(String str) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); c.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv.getBytes("UTF-8"))); byte[] byteStr = Base64.decodeBase64(str.getBytes()); return new String(c.doFinal(byteStr), "UTF-8"); }
From source file:by.bsuir.chujko.model.entities.security.StringCrypter.java
/** * To update secret key.// ww w. j ava 2s . co m * * @param key * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException * @throws InvalidKeyException */ private void updateSecretKey(SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { ecipher = Cipher.getInstance(key.getAlgorithm()); dcipher = Cipher.getInstance(key.getAlgorithm()); ecipher.init(Cipher.ENCRYPT_MODE, key); dcipher.init(Cipher.DECRYPT_MODE, key); }
From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.OracleObfuscation.java
public byte[] decrypt(byte[] bytes) throws GeneralSecurityException { cipher.init(Cipher.DECRYPT_MODE, key, iv); // normally you could leave // out the IvParameterSpec // argument, but not with // Oracle/*w w w . j a v a 2s .c om*/ return cipher.doFinal(bytes); }
From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java
/** * Decrypts a byte[] encrypted by {@link #encrypt} method. * * @param c The encrypted HEX byte[].//w w w.jav a 2 s . c o m * @param key The key. * @return The decrypted string in a byte[]. */ public static byte[] decrypt(byte[] c, String key) { try { SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); return cipher.doFinal(Hex.decodeHex((new String(c).toCharArray()))); } catch (Exception e) { logger.warn("Could not decrypt byte[]", e); return null; } }
From source file:br.com.manish.ahy.kernel.util.HashUtil.java
private static Cipher getCipher(boolean enc) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128);/* w ww . ja v a 2s . c o m*/ SecretKeySpec skeySpec = new SecretKeySpec(getBytes(HEXES2), "AES"); Cipher cipher = Cipher.getInstance("AES"); if (enc) { cipher.init(Cipher.ENCRYPT_MODE, skeySpec); } else { cipher.init(Cipher.DECRYPT_MODE, skeySpec); } return cipher; }
From source file:com.bconomy.autobit.Encryption.java
public static byte[] decrypt(byte[] cyphertext, byte[] key) { if (keySpec == null) keySpec = new SecretKeySpec(key, "AES"); Cipher aes;/*from www . ja va2s . c om*/ try { aes = Cipher.getInstance("AES/ECB/PKCS5Padding"); aes.init(Cipher.DECRYPT_MODE, keySpec); return aes.doFinal(cyphertext); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { ex.printStackTrace(); } return new byte[0]; }
From source file:com.tremolosecurity.proxy.filters.RetreiveIdToken.java
@Override public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception { HashMap<String, OpenIDConnectIdP> idps = (HashMap<String, OpenIDConnectIdP>) GlobalEntries .getGlobalEntries().get(OpenIDConnectIdP.UNISON_OPENIDCONNECT_IDPS); OpenIDConnectIdP idp = idps.get(this.idpName); if (idp == null) { throw new ServletException("Could not find idp '" + this.idpName + "'"); }/*from w ww. j a va 2 s . c o m*/ Gson gson = new Gson(); String json = this.inflate(request.getParameter("refresh_token").getValues().get(0)); Token token = gson.fromJson(json, Token.class); byte[] iv = org.bouncycastle.util.encoders.Base64.decode(token.getIv()); IvParameterSpec spec = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, GlobalEntries.getGlobalEntries().getConfigManager() .getSecretKey(idp.getTrusts().get(this.trustName).getCodeLastmileKeyName()), spec); byte[] encBytes = org.bouncycastle.util.encoders.Base64.decode(token.getEncryptedRequest()); String refreshToken = new String(cipher.doFinal(encBytes)); OIDCSession session = idp.getSessionByRefreshToken(refreshToken); if (session == null) { response.setStatus(401); } else { response.getWriter().print(session.getIdToken()); } }
From source file:eml.studio.shared.util.Aes.java
/** * Aes Decryption/* www . ja v a 2 s . c o m*/ * * @param encryptBytes byte[] to be decrypted * @param decryptKey decryption key * @return * @throws Exception */ public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); Cipher cipher = Cipher.getInstance(ALGORITHMSTR); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES")); byte[] decryptBytes = cipher.doFinal(encryptBytes); return new String(decryptBytes); }
From source file:com.fengduo.bee.commons.security.EncryptBuilder.java
public String decrypt(String secret, String secretKey) { if (StringUtils.isEmpty(secret) || StringUtils.isEmpty(secretKey)) { return null; }/*from w w w. j a va2 s.c o m*/ // Key?16? if (secretKey.length() != 16) { logger.error("Key?16?"); return null; } try { return new String(doCrypt(secret, secretKey, new ICrypt() { @Override public void initCipher(SecretKey key, SecureRandom sr, Cipher cipher) throws InvalidKeyException { cipher.init(Cipher.DECRYPT_MODE, key, sr); } @Override public byte[] getCryptedData(String secret) { return Base64.decode(secret); } })); } catch (Exception e) { String info = secret + "\r\n" + ExceptionUtils.getFullStackTrace(e); logger.error(info); } return null; }
From source file:com.miyue.util.Cryptos.java
/** * AES, .// w w w . j a v a 2 s .c o m * * @param input Hex? * @param key ?AES? */ public static String aesDecrypt(byte[] input, byte[] key) { byte[] decryptResult = aes(input, key, Cipher.DECRYPT_MODE); return new String(decryptResult); }