Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Encrypt/Decrypt Password Field in Sybase

Encrypt/Decrypt Password Field in Sybase

Scheduled Pinned Locked Moved Database
helpdatabasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MWRivera
    wrote on last edited by
    #1

    Hi All, I ran into an issue when trying to Decrypt a password field that I had previously encrypted and was hoping someone could help. I'm using SQL Anywhere 10. I encrypted the password field with no issues, using the following trigger when a new record was added to the table: ALTER TRIGGER "encrypt_new_user_pwd" BEFORE INSERT ORDER 1 ON "QAS"."tableName" REFERENCING NEW AS newPwd FOR EACH ROW BEGIN Set newPwd.pwdField = ENCRYPT(newPwd.pwdField , 'key') END The problem is I'm unable to decrypt the password of the newly created record (fieldID = 0002), using the following: SELECT CAST (DECRYPT(pwdField, 'key') AS VARCHAR(100)) FROM "QAS"."tableName" WHERE fieldID = '0002' In Sybase when trying to execute the above statement I get the following error: Interactive SQL The following error occurred while fetching results: Decryption error: Input must be a multiple of 16 bytes in length for AES SQLCODE=-851, ODBC 3 State="08001" Do you have any idea what's causing this error? The pwdField is of type VARCHAR and size 15. Thanks, Mel

    D 1 Reply Last reply
    0
    • M MWRivera

      Hi All, I ran into an issue when trying to Decrypt a password field that I had previously encrypted and was hoping someone could help. I'm using SQL Anywhere 10. I encrypted the password field with no issues, using the following trigger when a new record was added to the table: ALTER TRIGGER "encrypt_new_user_pwd" BEFORE INSERT ORDER 1 ON "QAS"."tableName" REFERENCING NEW AS newPwd FOR EACH ROW BEGIN Set newPwd.pwdField = ENCRYPT(newPwd.pwdField , 'key') END The problem is I'm unable to decrypt the password of the newly created record (fieldID = 0002), using the following: SELECT CAST (DECRYPT(pwdField, 'key') AS VARCHAR(100)) FROM "QAS"."tableName" WHERE fieldID = '0002' In Sybase when trying to execute the above statement I get the following error: Interactive SQL The following error occurred while fetching results: Decryption error: Input must be a multiple of 16 bytes in length for AES SQLCODE=-851, ODBC 3 State="08001" Do you have any idea what's causing this error? The pwdField is of type VARCHAR and size 15. Thanks, Mel

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      This is just a guess but if you read the error message it says:

      MWRivera wrote:

      Input must be a multiple of 16 bytes in length for AES

      But you say:

      MWRivera wrote:

      The pwdField is of type VARCHAR and size 15.

      Is 15 a multiple of 16? Make pwdField bigger and see if that helps.

      M 1 Reply Last reply
      0
      • D David Skelly

        This is just a guess but if you read the error message it says:

        MWRivera wrote:

        Input must be a multiple of 16 bytes in length for AES

        But you say:

        MWRivera wrote:

        The pwdField is of type VARCHAR and size 15.

        Is 15 a multiple of 16? Make pwdField bigger and see if that helps.

        M Offline
        M Offline
        MWRivera
        wrote on last edited by
        #3

        Hi David, Thanks for the reply. I changed the length of the field to 16 and this stopped the error message from displying, the only problem then was the password was showing up as squares. I then changed the length of the field to 80 (5x16=80) sticking with the multiple of 16 rule and it works great now. Thanks for your help with this it lead to me working it out. The reason I was recieving squares I asume is because the encrypted version of the password was larger than 16 and so the full encrypted version of it was too big to fit in the password field, therefore when I tried to decrypt it, it wasn't all there to decrypt and hence the nonsense squares. Thanks again, Mel

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups