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?


In reply to Re: MySQL AES Encryption with CBC mode by haukex
in thread MySQL AES Encryption with CBC mode by JayBee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.