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:io.hawkcd.agent.services.SecurityService.java

public String decrypt(String encrypted) {
    try {// w  ww  .j  a  va2  s  . c  om
        byte[] decodedValue = Base64.decodeBase64(getBytes(encrypted));
        Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
        byte[] decryptedValue = cipher.doFinal(decodedValue);
        String result = new String(decryptedValue);
        return result;
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}

From source file:com.searchcode.app.util.AESEncryptor.java

public byte[] decrypt(byte[] cipherText) throws Exception {
    SecretKeySpec secretKey = new SecretKeySpec(this.key, this.ALGORITHM);
    Cipher cipher = Cipher.getInstance(this.ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, secretKey);

    return cipher.doFinal(cipherText);
}

From source file:com.os.util.PasswordDecoderEncoder.java

public static String decrypt(String encryptPassword) throws Exception {
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    key = convertHexToBytes(keyst);/*from   w w  w .j  ava  2s  . co m*/
    final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    String encryptedString = new String(cipher.doFinal(Base64.decodeBase64(encryptPassword.getBytes())),
            "UTF-8");
    System.out.println(encryptedString);
    String passwordDecrypted = encryptedString.trim();

    return passwordDecrypted;

}

From source file:mx.bigdata.cfdi.CFDv3Debugger.java

public void dumpDigests() throws Exception {
    System.err.println(cfd.getOriginalString());
    byte[] digest = cfd.getDigest();
    CFDv3.dump("Digestion generada", digest, System.err);
    String certStr = cfd.document.getCertificado();
    Base64 b64 = new Base64();
    byte[] cbs = b64.decode(certStr);
    X509Certificate cert = KeyLoader.loadX509Certificate(new ByteArrayInputStream(cbs));
    cert.checkValidity();/*w w w.ja va2  s. com*/
    String sigStr = cfd.document.getSello();
    byte[] signature = b64.decode(sigStr);
    CFDv3.dump("Digestion firmada", signature, System.err);
    Cipher dec = Cipher.getInstance("RSA");
    dec.init(Cipher.DECRYPT_MODE, cert);
    byte[] result = dec.doFinal(signature);
    CFDv3.dump("Digestion decriptada", result, System.err);
    ASN1InputStream aIn = new ASN1InputStream(result);
    ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
    ASN1OctetString sigHash = (ASN1OctetString) seq.getObjectAt(1);
    CFDv3.dump("Sello", sigHash.getOctets(), System.err);
}

From source file:com.aqnote.shared.encrypt.symmetric.Blowfish.java

private static void generateCipher(String rawKey) {
    ProviderUtil.addBCProvider();//from ww w  .ja  va2  s.  c o  m
    encryptCipher = instanceCipher(CIPHER_NAME, PROVIDER_NAME);
    decryptCipher = instanceCipher(CIPHER_NAME, PROVIDER_NAME);
    key = generateKey(rawKey);
    iv = generateIV();
    initCipher(encryptCipher, Cipher.ENCRYPT_MODE, key, iv);
    initCipher(decryptCipher, Cipher.DECRYPT_MODE, key, iv);
}

From source file:com.iterzp.momo.utils.RSAUtils.java

/**
 * /*from   w  w w.  j a  v a 2  s.c  o  m*/
 * 
 * @param privateKey
 *            ?
 * @param data
 *            ?
 * @return ??
 */
public static byte[] decrypt(PrivateKey privateKey, byte[] data) {
    Assert.notNull(privateKey);
    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:com.earldouglas.xjdl.io.LicenseLoader.java

protected License decryptLicense(String encodedLicense)
        throws BadPaddingException, UnsupportedEncodingException, Exception {
    byte[] encryptedLicense = Base64.decodeBase64(encodedLicense);

    SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    byte[] serializedLicense = cipher.doFinal(encryptedLicense);

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedLicense);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    License license = (License) objectInputStream.readObject();
    objectInputStream.close();//from  w  w  w .  j  a  v  a 2s . com
    return license;
}

From source file:com.aerohive.nms.engine.admin.task.licensemgr.common.AerohiveEncryptTool.java

public AerohiveEncryptTool(String arg_Key) {
    if (arg_Key != null && !arg_Key.trim().equals(""))
        m_Str_Key = arg_Key;

    try {/*from ww w.  j  av a  2  s.co  m*/
        // Create the key
        KeySpec keySpec = new PBEKeySpec(m_Str_Key.toCharArray(), m_Byte_Salt, m_Int_IterationCount);
        SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
        m_Cipher_Ecipher = Cipher.getInstance(key.getAlgorithm());
        m_Cipher_Dcipher = Cipher.getInstance(key.getAlgorithm());

        // Prepare the parameter to the ciphers
        AlgorithmParameterSpec paramSpec = new PBEParameterSpec(m_Byte_Salt, m_Int_IterationCount);

        // Create the ciphers
        m_Cipher_Ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
        m_Cipher_Dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
    } catch (Exception e) {
        //DebugUtil.commonDebugWarn(e.getMessage());
    }
}

From source file:com.parleys.server.frontend.web.ipad.filters.AESEncrypter.java

private AESEncrypter(final Key key) {
    try {/*  ww  w .  jav  a2  s . c  om*/
        ecipher = Cipher.getInstance("AES");
        dcipher = Cipher.getInstance("AES");
        ecipher.init(Cipher.ENCRYPT_MODE, key);
        dcipher.init(Cipher.DECRYPT_MODE, key);
    } catch (Exception e) {
        LOGGER.fatal(e);
        throw new RuntimeException("Error generating key");
    }
}

From source file:com.haulmont.timesheets.EncryptDecrypt.java

public EncryptDecrypt(String key) {
    try {/*from  www .  j  av a 2 s . com*/
        String data = new StringBuilder(SALT + key).reverse().toString();
        SecretKeySpec secretKey = new SecretKeySpec(DigestUtils.md5(data), "AES");
        AlgorithmParameterSpec paramSpec = new IvParameterSpec(INIT_VECTOR);
        eCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        dCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        eCipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);
        dCipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
    } catch (Exception e) {
        throw new RuntimeException("Exception while init cipher:", e);
    }
}