Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: MySQL AES Encryption with CBC mode

by haukex (Archbishop)
on May 16, 2017 at 08:35 UTC ( [id://1190364]=note: print w/replies, xml ) Need Help??


in reply to MySQL AES Encryption with CBC mode

It all leads to an error being generated.

What error is that exactly? I unfortunately don't have a MySQL instance handy here, but I do see that in DBRun("SET SESSION block_encryption_mode='aes-128-cbc'; SELECT ID, ... you are trying to run two SQL statements at once, which isn't supported by default, you should try splitting that into two DB calls.

In general, your code structure could be cleaned up a bit. For example, you use the older style calling of functions &DBCredentials, instead DBCredentials() is recommended nowadays. Declaring all your variables at the top of the script doesn't help much in achieving proper scoping - e.g. instead of having sub DBConnect set the $dbh variable that is outside its scope, you could have it return the new handle instead. Also, you unconditionally call &DBConnect; at the beginning of sub DBRun and DBDo, when it would make more sense to connect only once at the beginning of the script. Lastly but probably most importantly, instead of interpolation ("...(Password,'$Set{AESKey}', ...") you should use placeholders - see Bobby Tables.

I don't know what your reasons are for storing passwords encrypted - why are you not hashing them instead?

Replies are listed 'Best First'.
Re^2: MySQL AES Encryption with CBC mode
by JayBee (Scribe) on May 16, 2017 at 20:39 UTC

    Yes, running two commands as one is apparently the problem, but I'm not certain running them separate terminates the initial assigned "session" and reverts to defaults with the second command.

    I'm not 100% sure the difference between "encrypted" and "hashed". My best guess: hashed is one way; and encrypted can be decrypted... so my answer: I currently need the option to decrypt for additional software access (which is not to be tinkered with).

      running them separate terminates the initial assigned "session" and reverts to defaults with the second command.

      That's part of what I meant when I was talking about calling DBConnect every time DBRun or DBDo gets called: This will establish a new connection to the database for every command you run, so that will certainly cause the session to be ended and a new one begun. Have you tried to see what happens when you connect only once at the beginning of the script and then run your commands separately?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found