MySQL column encryption with Hibernate in Spring MVC











up vote
0
down vote

favorite












I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.



I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.



Here's the code that has got me furthest



@Column(name="disability_description")
@Length(max=500)
@ColumnTransformer(
read = "AES_DECRYPT(disability_description, 'mykey')",
write = "AES_ENCRYPT(?, 'mykey')"
)
private String disabilityDescription;


This, however, doesn't work as I get the following errors



org.hibernate.exception.GenericJDBCException: could not execute statement

java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1


Please point in the right direction. I am lost. Also mykey doesn't point to anything, I just entered a random word.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.



    I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.



    Here's the code that has got me furthest



    @Column(name="disability_description")
    @Length(max=500)
    @ColumnTransformer(
    read = "AES_DECRYPT(disability_description, 'mykey')",
    write = "AES_ENCRYPT(?, 'mykey')"
    )
    private String disabilityDescription;


    This, however, doesn't work as I get the following errors



    org.hibernate.exception.GenericJDBCException: could not execute statement

    java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1


    Please point in the right direction. I am lost. Also mykey doesn't point to anything, I just entered a random word.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.



      I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.



      Here's the code that has got me furthest



      @Column(name="disability_description")
      @Length(max=500)
      @ColumnTransformer(
      read = "AES_DECRYPT(disability_description, 'mykey')",
      write = "AES_ENCRYPT(?, 'mykey')"
      )
      private String disabilityDescription;


      This, however, doesn't work as I get the following errors



      org.hibernate.exception.GenericJDBCException: could not execute statement

      java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1


      Please point in the right direction. I am lost. Also mykey doesn't point to anything, I just entered a random word.










      share|improve this question













      I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.



      I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.



      Here's the code that has got me furthest



      @Column(name="disability_description")
      @Length(max=500)
      @ColumnTransformer(
      read = "AES_DECRYPT(disability_description, 'mykey')",
      write = "AES_ENCRYPT(?, 'mykey')"
      )
      private String disabilityDescription;


      This, however, doesn't work as I get the following errors



      org.hibernate.exception.GenericJDBCException: could not execute statement

      java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1


      Please point in the right direction. I am lost. Also mykey doesn't point to anything, I just entered a random word.







      spring hibernate spring-mvc






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 15:44









      Yanis K

      438




      438
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          I doubt that your column is not of type BINARY:



          Mysql Doc:




          AES_ENCRYPT() encrypts the string str using the key string key_str and
          returns a binary string containing the encrypted output.







          share|improve this answer





















          • Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
            – Yanis K
            Nov 22 at 16:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434384%2fmysql-column-encryption-with-hibernate-in-spring-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          I doubt that your column is not of type BINARY:



          Mysql Doc:




          AES_ENCRYPT() encrypts the string str using the key string key_str and
          returns a binary string containing the encrypted output.







          share|improve this answer





















          • Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
            – Yanis K
            Nov 22 at 16:05















          up vote
          0
          down vote



          accepted










          I doubt that your column is not of type BINARY:



          Mysql Doc:




          AES_ENCRYPT() encrypts the string str using the key string key_str and
          returns a binary string containing the encrypted output.







          share|improve this answer





















          • Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
            – Yanis K
            Nov 22 at 16:05













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          I doubt that your column is not of type BINARY:



          Mysql Doc:




          AES_ENCRYPT() encrypts the string str using the key string key_str and
          returns a binary string containing the encrypted output.







          share|improve this answer












          I doubt that your column is not of type BINARY:



          Mysql Doc:




          AES_ENCRYPT() encrypts the string str using the key string key_str and
          returns a binary string containing the encrypted output.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 15:58









          hasnae

          1,2551016




          1,2551016












          • Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
            – Yanis K
            Nov 22 at 16:05


















          • Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
            – Yanis K
            Nov 22 at 16:05
















          Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
          – Yanis K
          Nov 22 at 16:05




          Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
          – Yanis K
          Nov 22 at 16:05


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434384%2fmysql-column-encryption-with-hibernate-in-spring-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo