#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    113
    Rep Power
    16

    Call variables dynamicaly in encrypt function


    I've got several form variables

    Code:
    form.firstname
    form.firstname1
    form.firstname2
    form.firstname3 ect.....
    I'm putting these into a database with an update query that gets looped over, personnumber is the index and I need form.firstname1 to update the number in the form variable name.

    Code:
    INSERT INTO golf
              (First_Name)
              VALUES  <cfqueryparam CFSQLType="cf_sql_varchar" value="#Encrypt(FirstName & personNumber,'AES', 'HEX')#" />

    This query will run but it will encrypt form.firstname and append the number to it in a string so you'll get a value like Laura2, Laura3.

    I've tried EVALUATE and VARIABLE but both throw an error:
    The HEX algorithm is not supported by the Security Provider you have chosen.
    i've used evaluate and variable to do this in the past but for some reason the encrypt function seems to be gumming up the works.

    Any thoughts?

    Thanks,
    DSFX
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    The first problem is that you're using Encrypt() incorrectly. The parameters are: string, key, algorithm, then encoding. If personNumber is supposed to be the key/seed, it needs to be Encrypt( firstName, personNumber, 'AES', 'HEX' ).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    113
    Rep Power
    16
    Originally Posted by kiteless
    The first problem is that you're using Encrypt() incorrectly. The parameters are: string, key, algorithm, then encoding. If personNumber is supposed to be the key/seed, it needs to be Encrypt( firstName, personNumber, 'AES', 'HEX' ).
    Thats embarrasing... haha. I was past the point of being able to effectivly work on that yesterday, i should have walked away.

    This seems to have remedied the original issue i was having:
    Code:
    #Encrypt(evaluate('form.firstname' & personnumber),form.seckey, 'AES', 'HEX')#"
    As always thanks for your insight Kiteless.

    DSFX
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    You can avoid needing to use Evaluate() with structure syntax, e.g.:

    var encryptValue = form[ 'firstname' ] & form[ 'personnumber' ];
    var encryptResult = Encrypt( encryptValue, form.seckey, 'AES', 'HEX' );

    Note this also works with dynamic keys, such as:

    form[ 'firstname#counter#' ]

    So if the value of "counter" is 1, it would result in form[ 'firstname1' ]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    113
    Rep Power
    16
    Originally Posted by kiteless
    You can avoid needing to use Evaluate() with structure syntax, e.g.:

    var encryptValue = form[ 'firstname' ] & form[ 'personnumber' ];
    var encryptResult = Encrypt( encryptValue, form.seckey, 'AES', 'HEX' );

    Note this also works with dynamic keys, such as:

    form[ 'firstname#counter#' ]

    So if the value of "counter" is 1, it would result in form[ 'firstname1' ]
    Perfect, thats what i was looking for! how big is the performance hit with the evaluate function anyways?
  10. #6
  11. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    It used to be very high. I think it's gotten lower but there's still some overhead. It's best to avoid it where you can.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    113
    Rep Power
    16
    Originally Posted by kiteless
    It used to be very high. I think it's gotten lower but there's still some overhead. It's best to avoid it where you can.
    Thanks for all the help Kiteless.

IMN logo majestic logo threadwatch logo seochat tools logo