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
- decode(String string, boolean decode)
- decodeBasicAuth(String auth)
- decodeJavaOpts(String encodedJavaOpts)
- decodeToDoubleArray(String encoded)
- decrypt(String encryptedText, String password)
- deserializeFromString(String x)
- deserializeLogic(String logicString)
- encodeBasicHeader(final String username, final String password)
- encodeDoubleArray(double[] noData)