Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.ars.util;

import java.security.Key;
import java.security.spec.KeySpec;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;

/*import com.sun.crypto.provider.SunJCE;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;*/

/**
* @author Srini
*
*/
public class IDCheckAESEncryption {

/**
* @param raw
* @return encryptedVal
* @throws Exception
*//*
public static String encrypt(String raw) throws Exception {

System.out.println("encrypt() - raw passed is: " + raw);

Cipher c = getCipher(Cipher.ENCRYPT_MODE);

byte[] encryptedVal = c.doFinal(raw.getBytes("UTF-8"));
// return new BASE64Encoder().encode(encryptedVal);
return raw;
}

*//**
* @param encrypted
* @return decValue
* @throws Exception
*//*
public static String decrypt(String encrypted) throws Exception {

//byte[] decodedValue = new BASE64Decoder().decodeBuffer(encrypted);
byte[] decodedValue = new byte[0];
Cipher c = getCipher(Cipher.DECRYPT_MODE);
byte[] decValue = c.doFinal(decodedValue);

//return new String(decValue);
return encrypted;
}

*//**
* @param mode
* @return Cipher
* @throws Exception
*//*
private static Cipher getCipher(int mode) throws Exception {
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding", new SunJCE());

// a random Init. Vector. just for testing
byte[] iv = "e675f725e675f725".getBytes("UTF-8");

c.init(mode, generateKey(), new IvParameterSpec(iv));
return c;
}

*//**
* @return SecretKeySpec
* @throws Exception
*//*
private static Key generateKey() throws Exception {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
char[] password = "dC10UEIo87L$#6ww".toCharArray();
byte[] salt = "G00f3#0B$4@56zql".getBytes("UTF-8");

KeySpec spec = new PBEKeySpec(password, salt, 65536, 128);
SecretKey tmp = factory.generateSecret(spec);
byte[] encoded = tmp.getEncoded();
return new SecretKeySpec(encoded, "AES");

}
*/
}