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:edu.tufts.vue.util.Encryption.java
public static String decrypt(String encrypted) { try {/*from w ww. ja v a2 s. c om*/ if (cipher == null) cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, getKey()); byte[] encryptedBytes = hex.decode(encrypted.getBytes()); byte[] recoveredBytes = cipher.doFinal(encryptedBytes); String recovered = new String(recoveredBytes); return recovered; } catch (Exception ex) { ex.printStackTrace(); return encrypted; } }
From source file:DesEncrypter.java
DesEncrypter(String passPhrase) throws Exception { int iterationCount = 2; KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount); SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec); ecipher = Cipher.getInstance(key.getAlgorithm()); dcipher = Cipher.getInstance(key.getAlgorithm()); AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount); ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec); }
From source file:de.scrubstudios.srvmon.notificator.classes.Crypt.java
public static String decrypt(String key, String data) { byte[] decryptedData = null; SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); try {/*from w w w . j av a 2 s. c o m*/ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, keySpec); //decryptedData = cipher.doFinal(Base64.decode(data)); decryptedData = cipher.doFinal(Base64.decodeBase64(data)); //return new String(decryptedData); return new String(decryptedData); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(Crypt.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.jopss.logico.negocio.util.CriptoUtils.java
public static String desDecode(String texto, String chave) { Cipher dcipher;//from w ww .j av a 2s .c om SecretKey key; String decod = null; try { key = new SecretKeySpec(chave.getBytes(), 0, 8, "DES"); dcipher = Cipher.getInstance("DES"); dcipher.init(Cipher.DECRYPT_MODE, key); byte[] dec = Hex.decodeHex(texto.toCharArray()); byte[] utf8 = dcipher.doFinal(dec); decod = new String(utf8, "UTF8"); } catch (Exception e) { log.error(e); } return decod; }
From source file:BD.Encriptador.java
public static String Desencriptar(String textoEncriptado) throws Exception { String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {// w ww . j a va 2s. co m byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8")); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); byte[] plainText = decipher.doFinal(message); base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { } return base64EncryptedString; }
From source file:lib.clases_cripto.java
public static String Desencriptar(String textoEncriptado) throws Exception { String secretKey = "qualityinfosolutions"; //llave para desenciptar datos String base64EncryptedString = ""; try {/*from w ww. j av a 2 s. c o m*/ byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8")); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); byte[] plainText = decipher.doFinal(message); base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { } return base64EncryptedString; }
From source file:com.lingxiang2014.util.RSAUtils.java
public static byte[] decrypt(PrivateKey privateKey, byte[] data) { Assert.notNull(privateKey);//from w w w . java 2s . com Assert.notNull(data); try { Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", PROVIDER); cipher.init(Cipher.DECRYPT_MODE, privateKey); return cipher.doFinal(data); } catch (Exception e) { return null; } }
From source file:controlpac.EncryptHelper.java
public static String Desencriptar(String textoEncriptado) { String base64EncryptedString = ""; try {/*from ww w . ja v a2 s . c o m*/ byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));//Desencodea el texto en base64 MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); //Crea un hash con la clave elegida byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede");//Crea la clave Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); //Inicia el descifrado byte[] plainText = decipher.doFinal(message);//Descifra el texto base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { } return base64EncryptedString; }
From source file:com.salesmanager.core.util.EncryptionUtil.java
public static String decrypt(String key, String value) throws Exception { if (value == null || value.equals("")) return ""; // NEED TO UNDERSTAND WHY PKCS5Padding DOES NOT WORK // Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes()); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); byte[] outText; outText = cipher.doFinal(hexToBytes(value)); return new String(outText); }
From source file:de.fhdo.helper.DES.java
public static String decrypt(String Text) { try {//from w ww . java 2s .co m DESKeySpec keySpec = new DESKeySpec("schluessel_stdrepository15".getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(keySpec); byte[] encrypedPwdBytes = Base64.decodeBase64(Text); Cipher cipher = Cipher.getInstance("DES");// cipher is not thread safe cipher.init(Cipher.DECRYPT_MODE, key); byte[] plainTextPwdBytes = (cipher.doFinal(encrypedPwdBytes)); return new String(plainTextPwdBytes); } catch (Exception e) { e.printStackTrace(); } return ""; }