/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Query to get data with AES_Decrypt

Hello,

I am trying to reterive data from a database. Here is my query:

[quote]

SELECT snpk, snloy, snkvv, snpn, snpop, snpo, snos, AES_DECRYPT( snhk, ‘encrypt’ ) AS snhk, snen, snsn, AES_DECRYPT( SSN, ‘encrypt’ ) AS SSN FROM sibl_table
WHERE SSN = ‘$SSN’

[/quote]

Could someone please tell me what mistake I am making? I get 0 results although there’s data in the table.

Thanks in advance

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 24.2008 — I'm not sure what the sequence of events is, but if the WHERE clause is processed first to determine which rows to select, you may have to apply the decryption to SSN there, too, as in that case the decryption within the field list has not yet been done.
Copy linkTweet thisAlerts:
@OombongoauthorJul 24.2008 — indeed, this is annoying. As long as I don't use WHERE SSN='$SSN', it works

I also tried WHERE SSN=$SSN (without quotes) and the result is the same ?
Copy linkTweet thisAlerts:
@NogDogJul 24.2008 — What I was getting at is you may need to do...
<i>
</i>. . . WHERE AES_DECRYPT(SSN, 'encrypt) = '$SSN'
...because the WHERE clause probably gets evaluated first to determine which rows to select, i.e. before the field list is selected.
Copy linkTweet thisAlerts:
@OombongoauthorJul 24.2008 — Found the solution. Quite unusual I must say:

<i>
</i>SELECT snpk,snloy,snkvv,snpn,snpop,snpo,snos,AES_DECRYPT(snhk,'encrypt') as snhk,snen,snsn,SSN,AES_DECRYPT(SSN,'encrypt') as SSNa FROM sibl_table WHERE SSN = AES_ENCRYPT('$SSN','encrypt')
Copy linkTweet thisAlerts:
@NogDogJul 24.2008 — That's probably more efficient, as the variable only needs to be encrypted once. ?
×

Success!

Help @Oombongo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...