Example usage for javax.crypto Cipher DECRYPT_MODE

List of usage examples for javax.crypto Cipher DECRYPT_MODE

Introduction

In this page you can find the example usage for javax.crypto Cipher DECRYPT_MODE.

Prototype

int DECRYPT_MODE

To view the source code for javax.crypto Cipher DECRYPT_MODE.

Click Source Link

Document

Constant used to initialize cipher to decryption mode.

Usage

From source file:com.agiletec.aps.util.DefaultApsEncrypter.java

public static String decrypt(String source) {
    try {//from   w  ww .j  a  va2s. c o  m
        Key key = getKey();
        Cipher desCipher = Cipher.getInstance(TRIPLE_DES);
        byte[] dec = Base64.decodeBase64(source.getBytes());
        desCipher.init(Cipher.DECRYPT_MODE, key);
        byte[] cleartext = desCipher.doFinal(dec);
        // Return the clear text
        return new String(cleartext);
    } catch (Throwable t) {
        throw new RuntimeException("Error decrypting string", t);
    }
}

From source file:com.liferay.sync.engine.util.Encryptor.java

public static String decrypt(String value) throws Exception {
    if (value == null) {
        return "";
    }//from ww  w  .  j a v  a 2  s  .  c o  m

    SecretKey secretKey = new SecretKeySpec(_PASSWORD, _ALGORITHM);

    Cipher cipher = Cipher.getInstance(_ALGORITHM);

    cipher.init(Cipher.DECRYPT_MODE, secretKey);

    String decryptedValue = value;

    for (int i = 0; i < _ITERATIONS; i++) {
        byte[] decodedBytes = Base64.decodeBase64(decryptedValue);

        byte[] decryptedBytes = cipher.doFinal(decodedBytes);

        decryptedValue = new String(decryptedBytes, _UTF8_CHARSET).substring(_SALT_LENGTH);
    }

    return decryptedValue;
}

From source file:encryptdecrypt.util.Security.java

public static String decrypt(String strToDecrypt) {
    try {/*from   w  w w. j  av  a 2  s .  c  o  m*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
        final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        return new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt.getBytes())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.vico.license.util.rsa.RSAdoDecrypt.java

public static String decrypt(String cryptograph) throws Exception {
    Key privateKey;// w w w .j  a  v a  2s. c o m
    String path = Thread.currentThread().getContextClassLoader().getResource("/").toURI().getPath();
    ObjectInputStream ois = null;
    try {
        /** ? */
        ois = new ObjectInputStream(new FileInputStream(path + FileNames.PRIVATEKEY_NAME));
        privateKey = (Key) ois.readObject();
    } catch (Exception e) {
        throw e;
    } finally {
        ois.close();
    }

    /** Cipher?RSA */
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, privateKey);

    /** ? */
    byte[] b1 = Base64.decodeBase64(cryptograph);
    /** ? */
    byte[] b = cipher.doFinal(b1);
    return new String(b);
}

From source file:Main.java

private static byte[] decryptWithPassphrase(byte[] encryptionSalt, int iterations, byte[] data,
        String passphrase) throws GeneralSecurityException, IOException {
    Cipher cipher = getCipherFromPassphrase(passphrase, encryptionSalt, iterations, Cipher.DECRYPT_MODE);
    return cipher.doFinal(data);
}

From source file:com.sysfore.pos.licensemanagement.LicenceManagementUtil.java

public static String decrypt(String strToDecrypt) {
    try {/*w w  w . j a va2  s  .c om*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
        final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        final String decryptedString = new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt)));

        return decryptedString;
    } catch (Exception e) {
        log.error("Error while decrypting", e);

    }
    return null;
}

From source file:Main.java

public static String decrypt(byte[] encryptionBytes)
        throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
    cipher.init(Cipher.DECRYPT_MODE, key);
    byte[] recoveredBytes = cipher.doFinal(encryptionBytes);
    String recovered = new String(recoveredBytes);
    return recovered;
}

From source file:DesEncrypter.java

DesEncrypter(SecretKey key) throws Exception {
    ecipher = Cipher.getInstance("DES");
    dcipher = Cipher.getInstance("DES");
    ecipher.init(Cipher.ENCRYPT_MODE, key);
    dcipher.init(Cipher.DECRYPT_MODE, key);
}

From source file:Main.java

public static void genMessageCiphers(char[] pass) {
    try {/* w  ww  . j  a  va 2 s .co m*/
        messageEncryptionCipher = genCipher(pass, messageSalt, KEY_FACTORY, ITERATION_COUNT,
                Cipher.ENCRYPT_MODE);
        messageDecryptionCipher = genCipher(pass, messageSalt, KEY_FACTORY, ITERATION_COUNT,
                Cipher.DECRYPT_MODE);
    } catch (Exception e) {
        Log.d(LOG_TAG, "genStorageCiphers", e);
    }
}

From source file:authentication.AES.java

public static String decrypt(String textoencriptado) throws Exception {
    Cipher decripta = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE");
    SecretKeySpec key = new SecretKeySpec(chaveencriptacao.getBytes("UTF-8"), "AES");
    decripta.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV.getBytes("UTF-8")));
    return new String(decripta.doFinal(Base64.decodeBase64(textoencriptado)), "UTF-8");
}