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:de.uzk.hki.da.utils.PasswordUtils.java
public static String decryptPassword(String password) { byte key[] = "394z57f4".getBytes(); byte decryptedPassword[]; try {//ww w.j ava 2 s . c om SecretKey secretKey = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(key)); Cipher decrypt = Cipher.getInstance("DES/CBC/PKCS5Padding"); decrypt.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(new byte[] { 0x01, 0x02, 0x04, 0x10, 0x01, 0x02, 0x04, 0x10 })); decryptedPassword = decrypt.doFinal(Base64.decodeBase64(password.getBytes())); } catch (GeneralSecurityException e) { throw new RuntimeException("Couldn't decrypt password " + password + e); } return new String(decryptedPassword); }
From source file:com.avbravo.avbravoutils.crypto.Encriptador.java
public static String decrypt(String key, String encrypted) throws Exception { Cipher cipher = Cipher.getInstance(cI); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), alg); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes()); byte[] enc = decodeBase64(encrypted); cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec); byte[] decrypted = cipher.doFinal(enc); return new String(decrypted); }
From source file:com.intera.roostrap.util.EncryptionUtil.java
public static void decrypt(String encryptionKey, InputStream is, OutputStream os) throws InvalidKeyException, IOException { encryptOrDecrypt(encryptionKey, Cipher.DECRYPT_MODE, is, os); }
From source file:com.ad.mediasharing.tvmclient.AESEncryption.java
public static byte[] decrypt(byte[] cipherBytes, String key, byte[] iv) throws Exception { Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM); AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(iv)); cipher.init(Cipher.DECRYPT_MODE, getKey(key), params); return cipher.doFinal(cipherBytes); }
From source file:com.doculibre.constellio.utils.aes.SimpleProtector.java
public static String decrypt(String encryptedValue) throws Exception { Key key = generateKey();// ww w. j a va2s .c o m Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.DECRYPT_MODE, key); byte[] decordedValue = Base64.decodeBase64(encryptedValue); byte[] decValue = c.doFinal(decordedValue); String decryptedValue = new String(decValue); return decryptedValue; }
From source file:com.lecaddyfute.utils.security.AESCrypto.java
public static String decrypt1(String encryptedData) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance(ALGO); keyGen.init(128);/* w w w.jav a2 s.c om*/ SecretKey key = keyGen.generateKey(); Cipher c = Cipher.getInstance(ALGO); c.init(Cipher.DECRYPT_MODE, key); // byte[] decordedValue = Base64.decodeBase64(encryptedData.getBytes()); // byte[] decValue = c.doFinal(decordedValue); byte[] decValue = c.doFinal(encryptedData.getBytes("UTF8")); String decryptedValue = new String(decValue); return decryptedValue; }
From source file:br.com.aws.odonto.utils.CipherUtil.java
public static synchronized String decrypt(String token) throws Exception { String tokenDecrypt = null;/*w ww .ja v a 2 s . c o m*/ try { byte[] strDecodeCipher = base64.decode(token.getBytes()); //System.out.println(" base64 decode: "+new String(strDecodeCipher)); cipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] decryptedData = cipher.doFinal(strDecodeCipher); tokenDecrypt = new String(decryptedData); //System.out.println("cipher decrypt: " +tokenDecrypt); } catch (Exception e) { e.printStackTrace(); throw e; } return tokenDecrypt; }
From source file:Main.java
private static PKCS8EncodedKeySpec decryptPrivateKey(byte[] encryptedPrivateKey) throws GeneralSecurityException { EncryptedPrivateKeyInfo epkInfo; try {//from w w w. j a va2s .co m epkInfo = new EncryptedPrivateKeyInfo(encryptedPrivateKey); } catch (IOException ex) { // Probably not an encrypted key. return null; } char[] password = System.console().readPassword("Password for the private key file: "); SecretKeyFactory skFactory = SecretKeyFactory.getInstance(epkInfo.getAlgName()); Key key = skFactory.generateSecret(new PBEKeySpec(password)); Arrays.fill(password, '\0'); Cipher cipher = Cipher.getInstance(epkInfo.getAlgName()); cipher.init(Cipher.DECRYPT_MODE, key, epkInfo.getAlgParameters()); try { return epkInfo.getKeySpec(cipher); } catch (InvalidKeySpecException ex) { System.err.println("Password may be bad."); throw ex; } }
From source file:com.java.demo.DesDemo.java
public static byte[] Decrypt(byte[] strBytes) { try {// www . j a v a2 s . c o m Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, convertSecretKey); byte[] result = cipher.doFinal(strBytes); return result; } catch (Exception e) { return null; } }
From source file:com.philosophy.LicenseDecoder.java
public LicenseDecoder(String text) { license = text;/*from www. j a v a2 s.co m*/ byte[] keyBytes = { 88, 42, 94, 52, 56, 81, 82, 98 }; System.out.println("Original License : " + license); try { SecretKey key = new SecretKeySpec(keyBytes, "DES"); Cipher cipher = Cipher.getInstance("DES"); byte[] decoded = Base64.decodeBase64(license.getBytes()); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decrypted = cipher.doFinal(decoded); System.out.println("Decrypted license : " + new String(decrypted)); } catch (NoSuchAlgorithmException e) { } catch (NoSuchPaddingException e) { } catch (InvalidKeyException e) { } catch (IllegalStateException e) { } catch (IllegalBlockSizeException e) { } catch (BadPaddingException e) { } }