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:Main.java
public static boolean decryptFile(byte[] key, byte[] iv, String sourceFilePath, String destFilePath) { return handleFile(Cipher.DECRYPT_MODE, key, iv, sourceFilePath, destFilePath); }
From source file:MainClass.java
public static void desEncrypt(String f1, String f2) throws Exception { SecretKey key = null;/*from w w w .jav a 2 s . c om*/ ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("DESKey.ser")); key = (SecretKey) keyFile.readObject(); keyFile.close(); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key); CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2)); int i; do { i = in.read(); if (i != -1) out.write(i); } while (i > 0); in.close(); out.close(); }
From source file:Main.java
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); return cipher.doFinal(encrypted); }
From source file:MainClass.java
public static void blowfishEncrypt(String f1, String f2) throws Exception { SecretKey key = null;/* www.ja v a 2 s .c o m*/ ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("BlowfishKey.ser")); key = (SecretKey) keyFile.readObject(); keyFile.close(); Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key); CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2)); int i; do { i = in.read(); if (i != -1) out.write(i); } while (i > 0); in.close(); out.close(); }
From source file:Main.java
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] decrypted = cipher.doFinal(encrypted); return decrypted; }
From source file:Main.java
public static byte[] decrypt(byte[] data, byte[] key, byte[] iv, String cipherAlgorithm) { try {//from ww w . j av a 2 s. c om Cipher cipher = initCipher(Cipher.DECRYPT_MODE, key, iv, cipherAlgorithm); return cipher.doFinal(data); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Decrypt data//from w ww .j av a2 s. com * @param secretKey - a secret key used for decryption * @param data - data to decrypt * @return Decrypted data * @throws Exception */ public static String decipher(String secretKey, String data) throws Exception { // Key has to be of length 8 if (secretKey == null || secretKey.length() != 8) throw new Exception("Invalid key length - 8 bytes key needed!"); SecretKey key = new SecretKeySpec(secretKey.getBytes(), ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, key); return new String(cipher.doFinal(toByte(data))); }
From source file:Main.java
public static String decrypt(byte[] cipherText) { SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = null;//from w w w . java2 s. c o m byte[] clearText = null; try { // init cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); clearText = cipher.doFinal(Base64.decode(new String(cipherText), 10)); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) {// TODO Auto-generated catch block e.printStackTrace(); } return new String(clearText); }
From source file:Main.java
public static byte[] decryptMessage(String key, byte[] input) throws Exception { if ((input == null) || (input.length <= 0)) { return null; }//from ww w . ja v a 2s. c o m try { return doFinal(key, Cipher.DECRYPT_MODE, input); } catch (Exception e) { throw new Exception("201"); } }
From source file:Main.java
/** * RSA decryption/*from www .j ava 2 s . co m*/ * @param priKey * @param message * @return * @throws IllegalBlockSizeException * @throws BadPaddingException * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException * @throws InvalidKeyException */ public static byte[] decryptRSA(RSAPrivateKey priKey, byte[] message) throws IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, priKey); return cipher.doFinal(message); }