Android DES encrypt decrypt(String property)

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

Description

decrypt

Declaration

static String decrypt(String property) 

Method Source Code

//package com.java2s;

import java.io.IOException;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

import android.util.Base64;

public class Main {
    private static final char[] PASSWORD = "enfldsgasdfasdfasdsgm"
            .toCharArray();// w  w w .  j ava2  s.c  om
    private static final byte[] SALT = { (byte) 0xde, (byte) 0x33,
            (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33,
            (byte) 0x10, (byte) 0x12, };

    static String decrypt(String property) {
        try {
            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(base64Decode(property)),
                    "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    private static byte[] base64Decode(String property) throws IOException {
        // NB: This class is internal, and you probably should use another impl
        return Base64.decode(property, Base64.DEFAULT);
    }
}

Related

  1. encode(String key, String data)
  2. desEncodeCBC(byte[] key, byte[] keyiv, byte[] data)
  3. desEncodeECB(byte[] key, byte[] data)
  4. encrypt(String property)
  5. encryptDES(String encryptString, String encryptKey)
  6. encryptDESFile(byte[] encryptdata, String encryptKey)
  7. encryptEDE(byte[] key, byte[] src)