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:de.mpg.escidoc.services.aa.crypto.RSAEncoder.java

public static String rsaDecrypt(String[] string) throws Exception {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrivateKey privateKey = (PrivateKey) readKeyFromFile(Config.getProperty("escidoc.aa.private.key.file"),
            false);// ww  w. ja  v a2  s  .  c o  m
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE, privateKey);
    for (String part : string) {
        byte[] inArr = Base64.decodeBase64(part.getBytes("UTF-8"));
        baos.write(cipher.doFinal(inArr));
        baos.flush();
    }

    return new String(baos.toByteArray(), "UTF-8");

}

From source file:com.vmware.fdmsecprotomgmt.PasswdEncrypter.java

/**
 * Decrypt the encrypted value with provided key
 *//*from   w w  w.  j av a2  s.  c o m*/
public static String decrypt(String key, String encryptedValue) {
    String decryptedString = null;
    try {
        IvParameterSpec iv = new IvParameterSpec(INIT_VECTOR.getBytes("UTF-8"));
        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

        decryptedString = new String(cipher.doFinal(Base64.decodeBase64(encryptedValue)));

    } catch (Exception ex) {
        System.out.println("Caught exception while decrypting string");
        ex.printStackTrace();
    }

    return decryptedString;
}

From source file:com.rdonasco.security.utils.EncryptionUtil.java

public static String decryptWithPassword(String encryptedString, String password) throws Exception {
    PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), SALT, COUNT);
    SecretKey pbeKey = getKeyFactory().generateSecret(pbeKeySpec);
    Cipher pbeCipher = Cipher.getInstance(CIPHER_KEY_SPEC);
    pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, PBE_PARAM_SPEC);
    byte[] decryptedBytes = pbeCipher.doFinal(Base64.decodeBase64(encryptedString));
    return new String(decryptedBytes);
}

From source file:com.charandeepmatta.oracle.sqldeveloper.DecodePasswordHash.java

private byte[] decryptPassword(final byte[] result) throws GeneralSecurityException {
    byte constant = result[0];
    if (constant != (byte) 5) {
        throw new IllegalArgumentException();
    }/*  w ww.j  a  va  2s  .c om*/
    byte[] secretKey = new byte[8];
    System.arraycopy(result, 1, secretKey, 0, 8);
    byte[] encryptedPassword = new byte[result.length - 9];
    System.arraycopy(result, 9, encryptedPassword, 0, encryptedPassword.length);
    byte[] iv = new byte[8];
    for (int i = 0; i < iv.length; i++) {
        iv[i] = 0;
    }
    Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secretKey, "DES"), new IvParameterSpec(iv));
    return cipher.doFinal(encryptedPassword);
}

From source file:com.jwt.security.auth.cryptographics.Crypto.java

public String decrypt(String ciphertext) throws InvalidKeySpecException {
    try {//from  ww w .  j  a  v a  2 s .c om
        SecretKey key = generateKey(cryptoProps.getSalt(), cryptoProps.getPassphrase());
        byte[] decrypted = doFinal(Cipher.DECRYPT_MODE, key, cryptoProps.getIv(), base64(ciphertext));
        return new String(decrypted, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw fail(e);
    }
}

From source file:Clases.cCifrado.java

public String Desencriptar(String textoEncriptado) {

    String secretKey = "MARSOFT"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {//from  w w w.  j  a va2s  . 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:jatoo.properties.FileProperties.java

public FileProperties(File file, Key key) throws GeneralSecurityException {

    this.file = file;

    cipherEncrypt = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipherEncrypt.init(Cipher.ENCRYPT_MODE, key);

    cipherDecrypt = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipherDecrypt.init(Cipher.DECRYPT_MODE, key);
}

From source file:com.qubole.quark.catalog.db.encryption.MysqlAES.java

public String convertToEntityAttribute(String phrase) throws SQLException {
    try {// w ww  . j  av a2  s .  c  o  m
        Cipher decryptCipher = Cipher.getInstance("AES");
        decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(this.key, "UTF-8"));

        return new String(decryptCipher.doFinal(Hex.decodeHex(phrase.toCharArray())));
    } catch (Exception e) {
        throw new SQLException(e);
    }

}

From source file:com.jsmartframework.web.manager.TagEncrypter.java

private static Cipher getDecryptCipher(HttpServletRequest request) throws Exception {
    Cipher decryptCipher = (Cipher) request.getAttribute(REQUEST_TAG_DECRYPT_CIPHER);
    if (decryptCipher == null) {
        decryptCipher = Cipher.getInstance("AES");
        decryptCipher.init(Cipher.DECRYPT_MODE, secretKey);
        request.setAttribute(REQUEST_TAG_DECRYPT_CIPHER, decryptCipher);
    }/*  w  w  w .  j  ava2 s .c  o  m*/
    return decryptCipher;
}

From source file:com.blackcrowsys.sinscrypto.AesEncryptor.java

@Override
public String decrypt(String secretkey, String iv, String toDecrypt)
        throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException,
        BadPaddingException, InvalidAlgorithmParameterException, DecoderException {
    Cipher cipher = Cipher.getInstance(AESMODE);
    SecretKeySpec secretKeySpec = new SecretKeySpec(secretkey.getBytes(), AES);
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(Hex.decodeHex(iv.toCharArray())));
    return new String(cipher.doFinal(Base64.decodeBase64(toDecrypt)));
}