mercredi 13 avril 2016

String to String Type Conversion in Struts 2 not working?

I want to encrypt user input and store it in a database. I am using Struts 2 type conversion, all user input is treated as a String, and conversions such as the following work correctly:

  • String to Integer
  • String to Long
  • String to byte[]

But when I attempt a conversion to the target type: String, it does not work and the convertFromString() method is not invoked.

@Override
public Object convertFromString(Map context, String[] value, Class arg2) {
    String val = value[0];      

    try {
        return ASEEncDecUtil.encrypt(val.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }

}

I am unable to figure out what am I doing wrong.

Is there a best practice that should be used to encrypt user input?

Aucun commentaire:

Enregistrer un commentaire