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
private static byte[] decrypt(byte[] key, byte[] encrypted) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()])); return cipher.doFinal(encrypted); }
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, new IvParameterSpec(new byte[cipher.getBlockSize()])); byte[] decrypted = cipher.doFinal(encrypted); return decrypted; }
From source file:Main.java
public static byte[] decrypt(byte[] data, byte[] key) throws Exception { SecretKey secretKey = new SecretKeySpec(key, "DESede"); Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] plainBytes = cipher.doFinal(data); return plainBytes; }
From source file:Main.java
public static byte[] decryptData(byte[] encryptedData, PrivateKey privateKey) { try {// ww w . j ava 2 s. c o m Cipher cipher = Cipher.getInstance(RSA_CHPHER_ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, privateKey); return cipher.doFinal(encryptedData); } catch (Exception e) { return null; } }
From source file:Main.java
public static String decryptData(String encryptBase64Data, String keyBase64) { SecretKeySpec key = new SecretKeySpec(Base64.decode(keyBase64, Base64.DEFAULT), "DES"); Cipher decipher = null;//w w w . jav a2 s . c o m try { decipher = Cipher.getInstance("DES"); decipher.init(Cipher.DECRYPT_MODE, key); byte[] encryptData = Base64.decode(encryptBase64Data, Base64.DEFAULT); return new String(decipher.doFinal(encryptData), "UTF8"); } catch (Exception e) { } return null; }
From source file:Main.java
public static byte[] desEncrypt(byte[] data, String key) throws Exception { try {/* w ww.j ava 2 s. c o m*/ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); byte[] base64Key = Base64.decode(key, Base64.DEFAULT); SecretKeySpec keyspec = new SecretKeySpec(base64Key, "AES"); cipher.init(Cipher.DECRYPT_MODE, keyspec); byte[] original = cipher.doFinal(data); return original; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static byte[] getDesCode(Context mContext, byte[] byteD) { Cipher cipher;//from w ww . jav a 2 s.com byte[] byteFina = null; try { cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, getKey(mContext)); byteFina = cipher.doFinal(byteD); } catch (Exception e) { e.printStackTrace(); } finally { cipher = null; } return byteFina; }
From source file:Main.java
public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128, new SecureRandom(decryptKey.getBytes())); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES")); byte[] decryptBytes = cipher.doFinal(encryptBytes); return new String(decryptBytes); }
From source file:Main.java
public static byte[] ees3DecodeECB(byte[] key, byte[] data) throws Exception { Key deskey = null;/*from w w w . jav a 2 s . c om*/ DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(data); return bOut; }
From source file:Main.java
public static byte[] decryptAES(SecretKey sKey, byte[] message) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Cipher c = Cipher.getInstance("AES"); c.init(Cipher.DECRYPT_MODE, sKey); return c.doFinal(message); }