Java XML Data Type Converter deCrypt(String property)

Here you can find the source of deCrypt(String property)

Description

de Crypt

License

Open Source License

Parameter

Parameter Description
property a parameter

Exception

Parameter Description
NoSuchAlgorithmException an exception
InvalidKeySpecException an exception
NoSuchPaddingException an exception
InvalidAlgorithmParameterException an exception
InvalidKeyException an exception
IOException an exception
BadPaddingException an exception
IllegalBlockSizeException an exception

Return

decrypted string

Declaration

public static String deCrypt(String property) throws NoSuchAlgorithmException, InvalidKeySpecException,
        NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IOException,
        BadPaddingException, IllegalBlockSizeException 

Method Source Code


//package com.java2s;
import javax.crypto.*;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

public class Main {
    private static final char[] PASSWORD = "sadlqewcirunqiakjsfhiruqowncgiop".toCharArray();
    private static final byte[] SALT = { (byte) 0xdc, (byte) 0x43, (byte) 0x17, (byte) 0x92, (byte) 0xdd,
            (byte) 0x63, (byte) 0x20, (byte) 0x72, };

    /**/*ww  w  .j  a v  a2s.  co  m*/
     * @param property
     * @return decrypted string
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     * @throws NoSuchPaddingException
     * @throws InvalidAlgorithmParameterException
     * @throws InvalidKeyException
     * @throws IOException
     * @throws BadPaddingException
     * @throws IllegalBlockSizeException
     */
    public static String deCrypt(String property) throws NoSuchAlgorithmException, InvalidKeySpecException,
            NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IOException,
            BadPaddingException, IllegalBlockSizeException {
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
        pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
        return new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(property)), "UTF-8");
    }
}

Related

  1. decode(String string, boolean decode)
  2. decodeBasicAuth(String auth)
  3. decodeJavaOpts(String encodedJavaOpts)
  4. decodeToDoubleArray(String encoded)
  5. decrypt(String encryptedText, String password)
  6. deserializeFromString(String x)
  7. deserializeLogic(String logicString)
  8. encodeBasicHeader(final String username, final String password)
  9. encodeDoubleArray(double[] noData)