Android Base64 Decode decryptBase64Text(String key, String src)

Here you can find the source of decryptBase64Text(String key, String src)

Description

decrypt Base Text

Declaration

public static String decryptBase64Text(String key, String src)
            throws Exception 

Method Source Code

//package com.java2s;

import javax.crypto.Cipher;

import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import android.util.Base64;

public class Main {
    private final static String encoding = "utf-8";
    private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };

    public static String decryptBase64Text(String key, String src)
            throws Exception {
        byte[] bytes = Base64.decode(src, Base64.DEFAULT);
        return decryptBytes(key, bytes);
    }/*w  w  w.  j  a  v  a 2s  .  co  m*/

    public static String decryptBytes(String key, byte[] src)
            throws Exception {
        byte[] bytes = decrypt(key.getBytes(), src);
        return new String(bytes, encoding);
    }

    private static byte[] decrypt(byte[] key, byte[] src) throws Exception {
        IvParameterSpec zeroIv = new IvParameterSpec(iv);
        SecretKeySpec spec = new SecretKeySpec(key, "DES");
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, spec, zeroIv);
        return cipher.doFinal(src);
    }
}

Related

  1. base16decode(String base16Str)
  2. base64Decode(final String text)
  3. base64ToText(String stringInput)
  4. from64(String a)
  5. fromBase64(String encoded)