+ Reply to Thread
Results 1 to 4 of 4

Thread: aes_encrypt/decrypt problem

  1. #1
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    aes_encrypt/decrypt problem

    I'm trying to setup a (relatively) simple encryption/decryption for a database I'm using. When I stepped into DB encryption a couple months ago, I found a really nice tutorial that did what I needed, but now I can't seem to track it down.

    Right now, I'm just trying to find out what I'm doing wrong. I have two columns in the table 'test': 'id' and 'data'. 'id' is just an AI INT and 'data' is a BINARY(128). Here's what I do as a test:
    Code:
    INSERT INTO test (data) VALUES (AES_ENCRYPT('The quick brown fox jumped over the lazy dogs.','0123456789abcdef'));
    
    And it claims success, showing me a bunch of binary gibberish in the data field. When I try to read it:
    Code:
    SELECT AES_DECRYPT(data,'0123456789abcdef') FROM test;
    
    it returns NULL... What am I doing wrong?

    Disregard. I found my problem. The data field needed to be 'BLOB', not BINARY. Feel free to remove this thread.
    Last edited by bryceowen; July 14th, 2009 at 02:50 PM. Reason: Found the problem.

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Just a guess -- could it be the BINARY(128)? Seems to me that would append a bunch of 0x00 values to pad the result to 128 bytes -- which would cause the decrypt to fail. Does MySql have a datatype such as VARBINARY(128)?
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Thanks for the reply, Wolffy, but as I mentioned in my edit, the BINARY was the problem. I set it to BLOB and it works fine, now.

  4. #4
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Glad you got it sorted -- we probably cross posted.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO