• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Encrypt / Decrypt Deleting Leading Zero

Participant ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

As always when I'm totally stumped I fall back on the greatest support network ever. I'm having a problem where the leading zero from a string of submitted numbers is being lost, somewhere, in either the encrypt or decrypt (I think). Here's the sit:

1. Users input 10 digit numeric information
2. I use Not IsNumeric to verify that the information input are actually numbers
3. The submitted numbers are encrypted using encrypt with AES / HEX
4. Inserted into the MySQL DB using cfsqltype="cf_sql_varchar"
5. DB field is set to VARCHAR

Any thoughts on why either the system or DB might be deleting the leading zero? I'm wondering if I need to change the field type to BLOB or TEXT.

Thanks,
D
TOPICS
Advanced techniques

Views

903

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

Is the leading zero disappearing from your 10 digit numeric data or your encrypted Hexidecimal string? Have you tried encrypting / decrypting a test number in the same CF page to see if you're losing the digit as part of the encryption process or the DB?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

All,
I dumped everything and even tested new numbers and I got it working on my local (testing) system that shares the same DB as our staging area. I've uploaded to the staging area all the pages I worked on however the leading zero's are still not being displayed on the staging area. Very strange.

I'm not sure where to go from here.

D

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

I just tried the code below and it isn't dropping the leading 0.
Have you dumped out the value before going into the query? That will isolate the problem to either your encryption or your query.
Post a snippet of how you're using encrypt/decrypt and maybe we can get a better idea of the problem.

<cfset key = GenerateSecretKey("AES")>
<cfset clearNum = "0123456789">
<cfset eNum = encrypt(clearNum,key,"AES","Hex")>
<cfoutput>#eNum#</cfoutput>
<hr>
<cfset dNum = decrypt(eNum,key,"AES","Hex")>
<cfoutput>#dNum#</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

I know you are using cf_varchar in your cfqueryparam but what datatype is the field you are inserting it into? If that is not a varchar then that'll be your problem!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

This could be a workaround: If the value after the decrypt is not 10 digits, add leading zeros until it becomes 10 digits.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

So you are using the same DB in both cases? Hmmm... Are you using different versions of CF on your development machine and your staging area? Worst case scenario, I'm thinking jdeline's suggestion is a pretty good hack to fix your issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 15, 2007 Jun 15, 2007

Copy link to clipboard

Copied

We are using the same version of CF on both sites. The only possible problem that I can see by procedurally changing the display of the digits to ensure that it's ten digits long is that we use those digits for processing other items. I will have to look into that.


D

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 15, 2007 Jun 15, 2007

Copy link to clipboard

Copied

LATEST
So you're using the save version of cf AND the same version of DB? And you're still getting different results on the 2 systems? Can you post the code that you use to encrypt / decrypt your 10 digit string?

I don't think jdeline was suggesting just changing the display of the digits to format it as a 10 digit number - I believe he was suggesting to add the leading zeros as soon as you decrypt the number. The only way I could see this being a problem is if you use the number in a system outside of CF (Java, .NET) before you have a chance to add the leading 0's.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation