package com.roly.nfc.crypto.util;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;

import android.util.Base64;

public class EncryptionUtils {

    public static String encrypt(SecretKey key, String stringToEncrypt) throws BadPaddingException,
            IllegalBlockSizeException,
            UnsupportedEncodingException,
            NoSuchPaddingException,
            NoSuchAlgorithmException,
            InvalidKeyException {

        Cipher ecipher = Cipher.getInstance("DES");

        ecipher.init(Cipher.ENCRYPT_MODE, key);

        // Encode the string into bytes using utf-8
        byte[] utf8 = stringToEncrypt.getBytes("UTF8");

        // Encrypt
        byte[] enc = ecipher.doFinal(utf8);
        // Encode bytes to base64 to get a string
        return Base64.encodeToString(enc,Base64.DEFAULT);

    }

    public static String decrypt(SecretKey key, String stringToDecrypt) throws BadPaddingException,
            IllegalBlockSizeException,
            UnsupportedEncodingException,
            NoSuchPaddingException,
            NoSuchAlgorithmException,
            InvalidKeyException {

        Cipher decipher = Cipher.getInstance("DES");

        decipher.init(Cipher.DECRYPT_MODE, key);
        // Decode base64 to get bytes
        byte[] dec = Base64.decode(stringToDecrypt.getBytes(),Base64.DEFAULT);

        // Decrypt
        byte[] utf8 = decipher.doFinal(dec);

        // Decode using utf-8
        return new String(utf8, "UTF8");

    }
}

@@ -162,17 +162,16 @@
 eption;%0A
-%0A
 import j
@@ -270,32 +270,66 @@
 kSizeException;%0A
+import javax.crypto.KeyGenerator;%0A
 import javax.cry
@@ -417,16 +417,16 @@
 ase64;%0A%0A
-
 public c
@@ -445,24 +445,255 @@
 ionUtils %7B%0A%0A
+    public static SecretKey generateKey() throws NoSuchAlgorithmException %7B%0A        SecretKey key;%0A        KeyGenerator generator = KeyGenerator.getInstance(%22DES%22);%0A        key = generator.generateKey();%0A        return key;%0A    %7D%0A%0A
     public s

Add generateKey method in EncryptionUtils